List.ItemCommand Evento

Definición

Se produce cuando el usuario selecciona un comando que está asociado a un control List. Esta API está obsoleta. Para obtener información sobre cómo desarrollar aplicaciones móviles ASP.NET, consulte 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 

Tipo de evento

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el ItemCommand evento para llamar a un método que cambia el estado de un elemento de la lista y vuelve a calcular los totales de estado. Este ejemplo forma parte de un ejemplo más grande para la List información general.

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

Comentarios

Cuando se representa una lista mediante plantillas, se llama al ItemCommand controlador de eventos a través del mecanismo de propagación de eventos de ASP.NET. El controlador de eventos se pasa un argumento de tipo ListCommandEventArgs, que contiene información sobre el elemento de origen y la CommandName propiedad del control que generó el evento. Esto le permite representar un único elemento de lista con varias interacciones asociadas.

En la representación predeterminada, el control proporciona una interfaz de usuario (UI) básica que permite al usuario hacer clic en elementos de lista. En postback, se llama al ItemCommand controlador de eventos con un argumento de tipo ListCommandEventArgs, que contiene información sobre el elemento de origen. La CommandName propiedad de este objeto es null.

Se aplica a

Consulte también