ObjectListCommand Class

Represents a command in an ObjectList ASP.NET mobile control.

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

public class ObjectListCommand
public class ObjectListCommand
public class ObjectListCommand
Not applicable.

An ObjectListCommand object can be declared as a <command> element within the declaration of an ObjectList.

An ObjectListCommand object can be also constructed, and added programmatically to an ObjectList, by adding it to the control's Commands member collection.

The following example shows how to create an ObjectListCommand object. This example is part of a larger, more complete example for the ObjectList overview.

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    //System.Web.UI.MobileControls.ObjectListItem item;
    //System.Web.UI.MobileControls.ObjectListItemCollection itemColl;
    // Get the persisted array through postbacks.
    ArrayList arr = new ArrayList();
    public void Page_Load(Object sender, EventArgs e)
        if (!IsPostBack)
            // Create and fill the array
            arr.Add(new Task("Tomorrow's work", "Yes", 1));
            arr.Add(new Task("Today's work", "Yes", 1));
            arr.Add(new Task("Yesterday's work", "No", 1));
            // Persist the array in the Session object
            Session["MyArrayList"] = arr;

            // Associate and bind array to the 
            // ObjectList for each postback.
            ObjectList1.DataSource = arr;
            ObjectList1.LabelField = "TaskName";

    private void ItemCommand_Click(Object sender, 
        ObjectListCommandEventArgs e)
        // Get the array from the Session object
        arr = (ArrayList)Session["MyArrayList"];

        // Remove selected item from the ObjectLis
        int i = ObjectList1.SelectedIndex;
        Session["MyArrayList"] = arr;

        // Re-Bind ObjectList to altered ArrayList.
        ObjectList1.DataSource = arr;
        ObjectList1.LabelField = "TaskName";
        ObjectList1.ViewMode = ObjectListViewMode.List;

    void ItemCommands_Show(Object sender, 
        ObjectListShowCommandsEventArgs e) 
        // Check conditions, and add or remove 
        // commands in the detail view.
        if (e.ListItem["Editable"].Equals("No"))
        else if (ObjectList1.Commands.Count < 1)
                ObjectListCommand("Delete", "Delete"));

    private class Task
        private string _TaskName;
        private string _Editable;
        private int _Days;
        public Task(string TaskName, string Editable, int Days)
            _TaskName = TaskName;
            _Editable = Editable;
            _Days = Days;
        public string TaskName
        { get { return _TaskName; } }
        public string Editable
        { get { return _Editable; } }
        public int Days
        { get { return _Days; } }

<html xmlns="http://www.w3.org/1999/xhtml" >
    <mobile:Form runat="server" id="Form1" >
        <mobile:ObjectList runat="server" id="ObjectList1" 
            OnShowItemCommands="ItemCommands_Show" >
            <Command Name="Delete" Text="Delete" />
        <mobile:Label runat="server" id="Label1" />
        <mobile:Label runat="server" id="Label2" />

  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1