Command.ItemCommand Evento

Definizione

Si verifica quando l'utente seleziona un comando è associato a un elemento ObjectList. Questa API è obsoleta. Per informazioni su come sviluppare applicazioni ASP.NET per dispositivi mobili, vedere App per dispositivi mobili & Siti con ASP.NET.

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

Tipo evento

Esempio

Nell'esempio di codice seguente viene illustrato come usare l'evento ItemCommand per più comandi in una pagina.

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

<script runat="server">
    void cmd_OnItemCommand(object sender, CommandEventArgs e)
    {
        // Create variables for data
        string txt1 = "Today's quote of {0} is {1}";
        string txt2 = "Yesterday's quote of {0} was {1}";
        int val = (Convert.ToInt32(e.CommandArgument) - 5);
        
        // Set the text values of the labels
        message1.Text = String.Format(txt1, e.CommandName, 
            e.CommandArgument);
        message2.Text = String.Format(txt2, e.CommandName, val);
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <p>
            <mobile:label id="message1" runat="server">
                Click the button for quotes
            </mobile:label>
            <mobile:label id="message2" runat="server" />
        </p>
        <mobile:command id="CmdA" Format="Link" 
            onItemCommand ="cmd_OnItemCommand" 
            CommandArgument="70" CommandName="ca" 
            runat="server" Text="Company A" />
        <mobile:command id="CmdB" Format="Link" 
            onItemCommand ="cmd_OnItemCommand" 
            CommandArgument="25" CommandName="cb" 
            runat="server" Text="Company B" />
        <mobile:command id="CmdC" Format="Button" 
            OnItemCommand ="cmd_OnItemCommand" 
            CommandArgument="110" CommandName="cc" 
            runat="server" Text= "Company C" />
    </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">
    Private Sub cmd_OnItemCommand(ByVal sender As Object, ByVal e As CommandEventArgs)
        ' Create variables for data
        Dim txt1 As String = "Today's quote of {0} is {1}"
        Dim txt2 As String = "Yesterday's quote of {0} was {1}"
        Dim Val As Integer = (Convert.ToInt32(e.CommandArgument) - 5)
        
        ' Set the text values of the labels
        message1.Text = String.Format(txt1, e.CommandName, _
            e.CommandArgument)
        message2.Text = String.Format(txt2, e.CommandName, Val)
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <p>
            <mobile:label id="message1" runat="server">
                Click the button for quotes
            </mobile:label>
            <mobile:label id="message2" runat="server" />
        </p>
        <mobile:command id="CmdA" Format="Link" 
            onItemCommand="cmd_OnItemCommand"
            CommandArgument="70" CommandName="ca" 
            runat="server" Text="Company A" />
        <mobile:command id="CmdB" Format="Link"
            onItemCommand ="cmd_OnItemCommand" 
            CommandArgument="25" CommandName="cb" 
            runat="server" Text="Company B" />
        <mobile:command id="CmdC" Format="Button" 
            OnItemCommand="cmd_OnItemCommand"
            CommandArgument="110" CommandName="cc" 
            runat="server" Text="Company C" />
    </mobile:form>
</body>
</html>

Commenti

Quando viene definito un ItemCommand gestore eventi, il Command controllo invia una notifica al gestore quando viene generato un evento di elemento tramite l'interazione dell'utente.

A differenza dell'evento, l'evento ClickItemCommand viene visualizzato in bolle fino ai controlli padre. Il ItemCommand rendering degli eventi è specifico del dispositivo e viene descritto in dettaglio nella sezione "Comportamento specifico del dispositivo" di System.Web.UI.MobileControls.Command.

L'evento OnItemCommand viene generato dopo un OnClick evento. In uno scenario in cui si ripete lo stesso set di azioni ogni volta che si fa clic su un pulsante di comando, è possibile usare la CommandName proprietà o CommandArgument del controllo per identificare il Command pulsante di comando selezionato dall'utente.

Si applica a

Vedi anche