Command.Format 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 Command 的呈現樣式。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 mobile Apps & Sites with ASP.NET。
public:
property System::Web::UI::MobileControls::CommandFormat Format { System::Web::UI::MobileControls::CommandFormat get(); void set(System::Web::UI::MobileControls::CommandFormat value); };
[System.ComponentModel.Bindable(true)]
public System.Web.UI.MobileControls.CommandFormat Format { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Format : System.Web.UI.MobileControls.CommandFormat with get, set
Public Property Format As CommandFormat
屬性值
CommandFormat 值,指出 Command 的呈現樣式。
- 屬性
範例
下列範例示範如何使用 Format 屬性將命令轉譯為連結或按鈕。
注意
下列程式代碼範例會使用單一檔案程式代碼模型,如果直接複製到程式代碼後置檔案,可能無法正常運作。 此程式代碼範例必須複製到擴展名為 .aspx 的空白文本檔。 如需詳細資訊,請參閱 ASP.NET Web Forms Page Code Model。
<%@ 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>
備註
透過列舉存取兩個 CommandFormat 可用的類型。
CommandFormat.Button (預設)
命令會轉譯為按鈕。
CommandFormat.Link
命令會轉譯為連結。
注意
屬性 Format 只支援 CommandFormat.Link 支援 JavaScript 的裝置上的值,如 屬性所 HttpCapabilitiesBase.JavaScript 指示。