ListCommandEventArgs.DefaultCommand Campo

Definizione

Imposta o restituisce il nome del comando predefinito. Questa API è obsoleta. Per informazioni su come sviluppare applicazioni per dispositivi mobili ASP.NET, vedere App per dispositivi mobili & Siti con ASP.NET.

protected: static initonly System::String ^ DefaultCommand;
protected static readonly string DefaultCommand;
 staticval mutable DefaultCommand : string
Protected Shared ReadOnly DefaultCommand As String 

Valore del campo

Esempio

Nell'esempio di codice seguente viene illustrato come usare la DefaultCommand proprietà per specificare "Check" come comando predefinito.

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 modello di codice 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">
    private void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Create array and add the tasks to it.
            ArrayList arr = new ArrayList();
            arr.Add(new Task("Verify transactions", "Done"));
            arr.Add(new Task("Check balance sheet", "Scheduled"));
            arr.Add(new Task("Send report", "Pending"));

            // Bind the List to the ArrayList
            ObjectList1.DataSource = arr;
            ObjectList1.DataBind();
        }
        ObjectList1.DefaultCommand = "Check";
    }

    // Event handler for all ObjectList1 commands
    private void SelectCommand(Object sender, 
        ObjectListCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "Check")
            ActiveForm = Form2;
        else if (e.CommandName.ToString() == "Browse")
            ActiveForm = Form3;
    }

    // Custom class for the ArrayList items
    private class Task
    {
        private String _TaskName, _Status;

        public Task(String TaskName, String Status)
        {
            _TaskName = TaskName;
            _Status = Status;
        }
        public String TaskName
        {
            get { return _TaskName; }
        }
        public String Status
        {
            get { return _Status; }
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="Form1" runat="server">
        <mobile:ObjectList runat="server" id="ObjectList1" 
            OnItemCommand="SelectCommand">
            <Command Name="Check" Text="Check Appointments" />
            <Command Name="Browse" Text="Browse Tasks" />
        </mobile:ObjectList>
    </mobile:form>
    <mobile:Form ID="Form2" Runat="server">
        <mobile:Label ID="Label1" Runat="server">
            Check Appointments</mobile:Label>
        <mobile:Link ID="Link1" Runat="server" 
            NavigateUrl="#Form1">Back</mobile:Link>
    </mobile:Form>
    <mobile:Form ID="Form3" Runat="server">
        <mobile:Label ID="Label2" Runat="server">
            Browse Tasks</mobile:Label>
        <mobile:Link ID="Link2" Runat="server" 
            NavigateUrl="#Form1">Back</mobile:Link>
    </mobile:Form>
</body>
</html>

Commenti

Se impostato, il ObjectList tentativo di eseguire il rendering di un collegamento per richiamare il comando predefinito. In HTML il rendering predefinito in ListView visualizza il primo campo come collegamento all'oggetto DetailsViewObjectList. Impostando la DefaultCommand proprietà, facendo clic sul collegamento viene richiamato il comando predefinito. Richiamando il comando predefinito viene generato l'evento ItemCommand . L'oggetto CommandNameObjectListCommandEventArgs è impostato sul valore della DefaultCommand proprietà.

Anche se viene definito un comando predefinito, è necessario includere un comando con lo stesso nome nell'insieme comandi. Se il controllo non riesce a eseguire il rendering di un elemento grafico che include un collegamento per il comando predefinito, il comando predefinito è ancora disponibile eseguendo il rendering della ObjectList.Commands raccolta.

Si applica a

Vedi anche