Command.Format Proprietà

Definizione

Ottiene o imposta lo stile di rendering per l'oggetto Command. Questa API è obsoleta. Per informazioni su come sviluppare applicazioni ASP.NET per dispositivi mobili, vedere App per dispositivi mobili & Siti con 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

Valore della proprietà

Valore CommandFormat che indica lo stile di rendering per l'oggetto Command.

Attributi

Esempio

Nell'esempio seguente viene illustrato come utilizzare la Format proprietà per eseguire il rendering del comando come collegamento o pulsante.

Nota

L'esempio di codice seguente usa il modello di codice a file singolo e potrebbe non funzionare correttamente se copiato direttamente in un file code-behind. Questo esempio di codice deve essere copiato in un file di testo vuoto con estensione aspx. Per altre informazioni, vedere Web Forms ASP.NET 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>

Commenti

Accedere ai due tipi disponibili tramite l'enumerazione CommandFormat .

CommandFormat.Button (impostazione predefinita)
Il rendering del comando viene eseguito come pulsante.

CommandFormat.Link
Il rendering del comando viene eseguito come collegamento.

Nota

La Format proprietà supporta il CommandFormat.Link valore solo nei dispositivi che supportano JavaScript, come indicato dalla HttpCapabilitiesBase.JavaScript proprietà .

Si applica a

Vedi anche