List.ItemCommand 事件

定義

使用者選取與 List 控制項相關聯的命令時會發生。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 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 

事件類型

範例

下列程式代碼範例示範如何使用 ItemCommand 事件來呼叫方法,以變更清單中的項目狀態,並重新計算狀態總計。 此範例是概觀較大範例的 List 一部分。

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 的事件反升機制來呼叫。 事件處理程式會傳遞 類型的 ListCommandEventArgs自變數,其中包含產生事件之控件的來源專案和 CommandName 屬性的相關信息。 這可讓您轉譯具有多個相關聯互動的單一列表專案。

在預設轉譯時,控件會提供基本的使用者介面 (UI) ,讓使用者按兩下清單專案。 在回傳時 ItemCommand ,事件處理程式會以 類型的 ListCommandEventArgs自變數呼叫,其中包含來源專案的相關信息。 這個 CommandName 物件的 屬性為 null

適用於

另請參閱