ListCommandEventArgs.DefaultCommand Field

Definition

Sets or returns the name of the default command. This API is obsolete. For information about how to develop ASP.NET mobile applications, see 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 

Field Value

Examples

The following code example demonstrates how to the use the DefaultCommand property to specify "Check" as the default command.

Note

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information, see 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">
    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>

Remarks

When set, the ObjectList attempts to render a shortcut to invoke the default command. In HTML, the default rendering in ListView displays the first field as a link to the DetailsView of the ObjectList. By setting the DefaultCommand property, clicking the link invokes the default command. Invoking the default command raises the ItemCommand event. The CommandName of the ObjectListCommandEventArgs object is set to the value of the DefaultCommand property.

Even if a default command is defined, you should include a command with the same name in the commands collection. If the control cannot render a graphical element that includes a shortcut for the default command, the default command is still available by rendering the ObjectList.Commands collection.

Applies to

See also