List.ItemCommand 事件

定义

在用户选择与 List 控件关联的命令时发生。Occurs when the user selects a command that is associated with a List control. 此 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::ListCommandEventHandler ^ ItemCommand;
public event System.Web.UI.MobileControls.ListCommandEventHandler ItemCommand;
member this.ItemCommand : System.Web.UI.MobileControls.ListCommandEventHandler 
Public Custom Event ItemCommand As ListCommandEventHandler 

事件类型

ListCommandEventHandler

示例

下面的代码示例演示如何使用 ItemCommand 事件来调用一个方法,该方法更改列表中某一项的状态并重新计算状态总计。The following code example shows how to use the ItemCommand event to call a method that changes the status of an item in the list and recalculates the status totals. 此示例摘自一个更大的 List 概述示例。This example is part of a larger example for the List overview.

private void Status_ItemCommand(object sender, 
    ListCommandEventArgs e)
{
    const string spec = "You now have {0} " + 
        "tasks done, {1} tasks scheduled, and " +
        "{2} tasks pending.";

    // Move selection to next status toward 'done'
    switch (e.ListItem.Value)
    {
        case "scheduled":
            schedCount -= 1;
            pendCount += 1;
            e.ListItem.Value = "pending";
            break;
        case "pending":
            pendCount -= 1;
            doneCount += 1;
            e.ListItem.Value = "done";
            break;
    }

    // Show the status of the current task
    Label1.Text = e.ListItem.Text + " is " +
        e.ListItem.Value;

    // Show current selection counts
    Label2.Text = String.Format(spec, doneCount, 
        schedCount, pendCount);
}
Private Sub Status_ItemCommand(ByVal sender As Object, _
    ByVal e As ListCommandEventArgs)

    Const spec As String = "You now have {0} tasks done, {1} " & _
        "tasks scheduled, and {2} tasks pending."

    ' Move selection to next status toward 'done'
    Select Case e.ListItem.Value
        Case "scheduled"
            schedCount -= 1
            pendCount += 1
            e.ListItem.Value = "pending"
        Case "pending"
            pendCount -= 1
            doneCount += 1
            e.ListItem.Value = "done"
            
    End Select

    ' Show the status of the current task
    Label1.Text = e.ListItem.Text & " is " & _
        e.ListItem.Value

    ' Show current selection counts
    Label2.Text = String.Format(spec, doneCount, _
        schedCount, pendCount)
End Sub

注解

使用模板呈现列表时,将 ItemCommand 通过 ASP.NET 的事件冒泡机制调用事件处理程序。When you render a list by using templates, the ItemCommand event handler is called through the event-bubbling mechanism of ASP.NET. 向事件处理程序传递一个类型为的参数 ListCommandEventArgs ,该参数包含有关源项和 CommandName 生成事件的控件的属性的信息。The event handler is passed an argument of type ListCommandEventArgs, 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 list item with multiple associated interactions.

默认呈现时,控件提供了一个 (UI) 的基本用户界面,该用户界面允许用户单击列表项。On default rendering, the control provides a basic user interface (UI) that allows the user to click list items. 在回发时, ItemCommand 使用类型为的参数调用事件处理程序 ListCommandEventArgs ,该参数包含有关源项的信息。On postback, the ItemCommand event handler is called with an argument of type ListCommandEventArgs, which contains information about the source item. CommandName此对象的属性为 nullThe CommandName property of this object is null.

适用于

另请参阅