This documentation is archived and is not being maintained.

ListCommandEventArgs::DefaultCommand Field

Sets or returns the name of the default command.

Namespace:  System.Web.UI.MobileControls
Assembly:  System.Web.Mobile (in System.Web.Mobile.dll)

protected:
static initonly String^ DefaultCommand

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.

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

NoteNote:

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1
Show: