Command.CommandArgument Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengatur atau mengembalikan argumen yang terkait dengan perintah dalam peristiwa tersebut ItemCommand . Nilai default adalah string kosong (""). API ini kedaluarsa. Untuk informasi tentang cara mengembangkan aplikasi seluler ASP.NET, lihat Situs & Mobile Apps dengan ASP.NET.
public:
property System::String ^ CommandArgument { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public string CommandArgument { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.CommandArgument : string with get, set
Public Property CommandArgument As String
Nilai Properti
Argumen yang terkait dengan perintah di ItemCommand.
- Atribut
Contoh
Contoh kode berikut menunjukkan cara menggunakan CommandArgument properti untuk menampilkan nilai.
Catatan
Contoh kode berikut menggunakan model kode file tunggal dan mungkin tidak berfungsi dengan benar jika disalin langsung ke file code-behind. Contoh kode ini harus disalin ke dalam file teks kosong yang memiliki ekstensi .aspx. Untuk informasi selengkapnya, lihat Model Kode Halaman Formulir Web ASP.NET.
<%@ 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>