Command.ItemCommand Zdarzenie
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Występuje, gdy użytkownik wybierze polecenie skojarzone z elementem ObjectList . 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::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
Typ zdarzenia
Przykłady
W poniższym przykładzie kodu pokazano, jak używać ItemCommand zdarzenia dla wielu poleceń na stronie.
<%@ 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>
Uwagi
Po zdefiniowaniu programu obsługi zdarzeń ItemCommand kontrolka Command powiadamia program obsługi, gdy zdarzenie elementu jest generowane za pośrednictwem interakcji użytkownika.
Click W przeciwieństwie do zdarzenia ItemCommand zdarzenie jest bąbelkowe do kontrolek nadrzędnych. Renderowanie ItemCommand zdarzenia jest specyficzne dla urządzenia i zostało szczegółowo omówione w sekcji "Zachowanie specyficzne dla urządzenia" w temacie System.Web.UI.MobileControls.Command.
Zdarzenie OnItemCommand jest zgłaszane po zdarzeniu OnClick . W scenariuszu, w którym powtarzasz ten sam zestaw akcji przy każdym kliknięciu przycisku polecenia, możesz użyć CommandName właściwości Command lub CommandArgument kontrolki, aby zidentyfikować przycisk polecenia kliknięty przez użytkownika.
Dotyczy
Zobacz też
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla