ObjectList.ItemCommand 이벤트

정의

사용자가 ObjectList 항목에 연결된 명령을 선택하면 이 이벤트가 발생합니다.Occurs when the user selects a command that is associated with an ObjectList item. 이 API는 더 이상 사용되지 않습니다.This API is obsolete. ASP.NET 모바일 애플리케이션을 개발하는 방법에 대한 자세한 내용은 Mobile Apps & Sites with ASP.NET(ASP.NET을 사용한 모바일 앱 및 사이트)을 참조하세요.For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.

public:
 event System::Web::UI::MobileControls::ObjectListCommandEventHandler ^ ItemCommand;
public event System.Web.UI.MobileControls.ObjectListCommandEventHandler ItemCommand;
member this.ItemCommand : System.Web.UI.MobileControls.ObjectListCommandEventHandler 
Public Custom Event ItemCommand As ObjectListCommandEventHandler 

예제

다음 코드 예제에서는 ItemCommand 이벤트를 트래핑 하는 방법을 보여 줍니다.The following code example demonstrates how to trap the ItemCommand event. CommandName 속성은 수행할 작업을 지정 합니다.The CommandName property specifies what action to perform.

참고

다음 코드 샘플 단일 파일 코드 모델을 사용 하 고 코드 숨김 파일에 직접 복사 하는 경우 제대로 작동 하지 않을 수 있습니다.The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. 이 코드 샘플.aspx 확장명이 있는 빈 텍스트 파일에 복사 해야 합니다.This code sample must be copied into an empty text file that has an .aspx extension. 자세한 내용은 ASP.NET Web Forms 페이지 코드 모델합니다.For more information, see ASP.NET Web Forms Page Code Model.

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    //System.Web.UI.MobileControls.ObjectListItem item;
    //System.Web.UI.MobileControls.ObjectListItemCollection itemColl;
    // Get the persisted array through postbacks.
    ArrayList arr = new ArrayList();
    public void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Create and fill the array
            arr.Add(new Task("Tomorrow's work", "Yes", 1));
            arr.Add(new Task("Today's work", "Yes", 1));
            arr.Add(new Task("Yesterday's work", "No", 1));
            
            // Persist the array in the Session object
            Session["MyArrayList"] = arr;

            // Associate and bind array to the 
            // ObjectList for each postback.
            ObjectList1.DataSource = arr;
            ObjectList1.LabelField = "TaskName";
            ObjectList1.DataBind();
        }
    }

    private void ItemCommand_Click(Object sender, 
        ObjectListCommandEventArgs e)
    {
        // Get the array from the Session object
        arr = (ArrayList)Session["MyArrayList"];

        // Remove selected item from the ObjectLis
        int i = ObjectList1.SelectedIndex;
        arr.RemoveAt(i);
        Session["MyArrayList"] = arr;

        // Re-Bind ObjectList to altered ArrayList.
        ObjectList1.DataSource = arr;
        ObjectList1.LabelField = "TaskName";
        ObjectList1.DataBind();
        ObjectList1.ViewMode = ObjectListViewMode.List;
    }

    void ItemCommands_Show(Object sender, 
        ObjectListShowCommandsEventArgs e) 
    {
        // Check conditions, and add or remove 
        // commands in the detail view.
        if (e.ListItem["Editable"].Equals("No"))
            ObjectList1.Commands.RemoveAt(0);
        else if (ObjectList1.Commands.Count < 1)
            ObjectList1.Commands.Add(new 
                ObjectListCommand("Delete", "Delete"));
    }

    private class Task
    {
        private string _TaskName;
        private string _Editable;
        private int _Days;
        public Task(string TaskName, string Editable, int Days)
        {
            _TaskName = TaskName;
            _Editable = Editable;
            _Days = Days;
        }
        public string TaskName
        { get { return _TaskName; } }
        public string Editable
        { get { return _Editable; } }
        public int Days
        { get { return _Days; } }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:Form runat="server" id="Form1" >
        <mobile:ObjectList runat="server" id="ObjectList1" 
            OnItemCommand="ItemCommand_Click" 
            OnShowItemCommands="ItemCommands_Show" >
            <Command Name="Delete" Text="Delete" />
        </mobile:ObjectList>
        <mobile:Label runat="server" id="Label1" />
        <mobile:Label runat="server" id="Label2" />
    </mobile:Form>
</body>
</html>
<%@ Page Language="VB" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    ' System.Web.UI.MobileControls.ObjectListItem item
    ' System.Web.UI.MobileControls.ObjectListItemCollection itemColl
    ' Get the persisted array through postbacks.
    Private arr As New ArrayList()
    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not IsPostBack Then
            ' Create and fill the array
            arr.Add(new Task("Tomorrow's work", "Yes", 1))
            arr.Add(new Task("Today's work", "Yes", 1))
            arr.Add(new Task("Yesterday's work", "No", 1))
            
            ' Persist the array in the Session object
            Session("MyArrayList") = arr

            ' Associate and bind array to the 
            ' ObjectList for each postback.
            ObjectList1.DataSource = arr
            ObjectList1.LabelField = "TaskName"
            ObjectList1.DataBind()
            
        End If
    End Sub

    Private Sub SelectCommand(ByVal sender As Object, _
         ByVal e As ObjectListCommandEventArgs)
        ' Get the array from the Session object
        arr = CType(Session("MyArrayList"), ArrayList)

        ' Remove selected item from the ObjectLis
        Dim i As Integer = ObjectList1.SelectedIndex
        arr.RemoveAt(i)
        Session("MyArrayList") = arr

        ' Re-Bind ObjectList to altered ArrayList.
        ObjectList1.DataSource = arr
        ObjectList1.LabelField = "TaskName"
        ObjectList1.DataBind()
        ObjectList1.ViewMode = ObjectListViewMode.List
    End Sub

    Public Sub ShowTaskDetail(ByVal sender As Object, _
        ByVal e As ObjectListShowCommandsEventArgs)

        ' Check conditions, and add or remove 
        ' commands in the detail view.
        If e.ListItem("Editable").Equals("No") Then
            ObjectList1.Commands.RemoveAt(0)
        ElseIf ObjectList1.Commands.Count < 1 Then
            ObjectList1.Commands.Add(New ObjectListCommand("Delete", "Delete"))
        End If
    End Sub

    Private Class Task
        Private _TaskName As String
        Private _Editable As String
        Private _Days As Integer
        Public Sub New(ByVal TaskName As String, _
            ByVal Editable As String, ByVal Days As Integer)

            _TaskName = TaskName
            _Editable = Editable
            _Days = Days
        End Sub
        Public ReadOnly Property TaskName() As String
            Get
                Return _TaskName
            End Get
        End Property
        Public ReadOnly Property Editable() As String
            Get
                Return _Editable
            End Get
        End Property
        Public ReadOnly Property Days() As Integer
            Get
                Return _Days
            End Get
        End Property
    End Class
</script>

<html xmlns="http:'www.w3.org/1999/xhtml" >
<body>
    <mobile:Form runat="server" id="Form1" >
        <mobile:ObjectList runat="server" id="ObjectList1" 
            OnItemCommand="SelectCommand" OnShowItemCommands="ShowTaskDetail" >
            <Command Name="Delete" Text="Delete" />
        </mobile:ObjectList>
        <mobile:Label runat="server" id="Label1" />
        <mobile:Label runat="server" id="Label2" />
    </mobile:Form>
</body>
</html>

설명

ItemCommand 이벤트 처리기가 정의 되 면 ObjectList는 사용자 상호 작용을 통해 항목 이벤트가 생성 될 때 처리기에 게 알립니다.When an ItemCommand event handler is defined, the ObjectList notifies the handler when an item event is generated through user interaction.

템플릿을 사용 하 여 개체 목록을 렌더링 하면 ASP.NET의 이벤트 버블링 메커니즘을 통해 ItemCommand 이벤트 처리기가 호출 됩니다.When you render an object list by using templates, the ItemCommand event handler is called through the event-bubbling mechanism of ASP.NET. 이벤트 처리기는 ObjectListCommandEventArgs형식의 인수를 전달 합니다 .이 인수에는 이벤트를 생성 한 컨트롤의 소스 항목 및 CommandName 속성에 대 한 정보가 포함 됩니다.The event handler is passed an argument of type ObjectListCommandEventArgs, which contains information about the source item and the CommandName property of the control that generated the event. 이 옵션을 사용 하면 여러 관련된 상호 작용을 사용 하 여 단일 항목을 렌더링할 수 있습니다.This allows you to render a single item with multiple associated interactions.

기본 렌더링 컨트롤 링크로 개체 목록에 대해 정의 된 명령의 각 렌더링 합니다.On default rendering, the control renders each of the commands defined for the object list as a link. 사용자가 링크를 클릭 하면 소스 항목에 대 한 정보가 포함 된 ObjectListCommandEventArgs형식의 인수를 사용 하 여 ItemCommand 이벤트 처리기가 호출 됩니다.When the user clicks a link, the ItemCommand event handler is called with an argument of type ObjectListCommandEventArgs, which contains information about the source item. CommandName 속성의 값은 사용자가 호출 하는 명령의 이름입니다.The value in the CommandName property is the name of the command that the user invoked.

적용 대상

추가 정보