ListCommandEventArgs.DefaultCommand Campo

Definición

Establece o devuelve el nombre del comando predeterminado. Esta API está obsoleta. Para obtener información sobre cómo desarrollar aplicaciones móviles ASP.NET, consulte Mobile Apps & Sites with ASP.NET.

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

Valor de campo

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la DefaultCommand propiedad para especificar "Check" como comando predeterminado.

Nota:

En el ejemplo de código siguiente se usa el modelo de código de un solo archivo y es posible que no funcione correctamente si se copia directamente en un archivo de código subyacente. Este ejemplo de código debe copiarse en un archivo de texto vacío que tenga una extensión .aspx. Para obtener más información, vea modelo de código de página de ASP.NET Web Forms.

<%@ 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>

Comentarios

Cuando se establece, intenta ObjectList representar un acceso directo para invocar el comando predeterminado. En HTML, la representación predeterminada en ListView muestra el primer campo como un vínculo a DetailsView de .ObjectList Al establecer la DefaultCommand propiedad , al hacer clic en el vínculo se invoca el comando predeterminado. Al invocar el comando predeterminado, se genera el ItemCommand evento . Del CommandNameObjectListCommandEventArgs objeto se establece en el valor de la DefaultCommand propiedad .

Incluso si se define un comando predeterminado, debe incluir un comando con el mismo nombre en la colección de comandos. Si el control no puede representar un elemento gráfico que incluye un acceso directo para el comando predeterminado, el comando predeterminado sigue estando disponible mediante la representación de la ObjectList.Commands colección.

Se aplica a

Consulte también