List.ItemCommand Zdarzenie

Definicja

Występuje, gdy użytkownik wybiera polecenie skojarzone z kontrolką List . Ten interfejs API jest nieaktualny. Aby uzyskać informacje na temat tworzenia ASP.NET aplikacji mobilnych, zobacz Mobile Apps & Sites with ASP.NET (Aplikacje mobilne & 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 

Typ zdarzenia

Przykłady

Poniższy przykład kodu przedstawia sposób użycia ItemCommand zdarzenia do wywołania metody, która zmienia stan elementu na liście i oblicza ponownie sumy stanu. Ten przykład jest częścią większego przykładu dla List omówienia.

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

Uwagi

Podczas renderowania listy przy użyciu szablonów ItemCommand program obsługi zdarzeń jest wywoływany za pomocą mechanizmu bubbling zdarzenia ASP.NET. Procedura obsługi zdarzeń jest przekazywana argument typu ListCommandEventArgs, który zawiera informacje o elemencie źródłowym i CommandName właściwości kontrolki, która wygenerowała zdarzenie. Umożliwia to renderowanie pojedynczego elementu listy z wieloma skojarzonymi interakcjami.

Podczas renderowania domyślnego kontrolka udostępnia podstawowy interfejs użytkownika, który umożliwia użytkownikowi klikanie elementów listy. W przypadku ogłaszania zwrotnego ItemCommand program obsługi zdarzeń jest wywoływany z argumentem typu ListCommandEventArgs, który zawiera informacje o elemencie źródłowym. Właściwość CommandName tego obiektu to null.

Dotyczy

Zobacz też