ObjectListCommandCollection Class

Represents a collection of ObjectListCommand objects.

public class System.Web.UI.MobileControls.ObjectListCommandCollection : 
   System.Web.UI.MobileControls.ArrayListCollectionBase,
   System.Web.UI.IStateManager

Remarks

The class object provides the container for the commands of an ObjectList control. Accessing the Commands property of an ObjectList control retrieves an ObjectListCommandCollection object. An application can programmatically add or remove commands.

The ObjectListCommandCollection class implements the System.Collections.ICollection interface through the System.Web.UI.MobileControls.ArrayListCollectionBase class.

Example

This example persists an array of tasks through multiple page loads and binds the array to an object list for display.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="c#" debug="true" %>

<script runat=server>

System.Web.UI.MobileControls.ObjectListItem item;
System.Web.UI.MobileControls.ObjectListItemCollection itemColl;

// Persist the array through subsequent page loads.
ArrayList arr = new ArrayList();

class Task
{
   private string _TaskName;
   private string _Editable;
   private int   _ Priority;
   
   public Task(string TaskName, string Editable, int Priority) 
   {
      _TaskName = TaskName; 
      _Editable = Editable;
      _Priority = Priority;
   }

   public string TaskName { get { return _TaskName; } }
   public string Editable { get { return _Editable; } }
   public int Priority { get { return _Priority; } }
}

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));
      // Associate and bind the array to ObjectList for each postback.
      Session["MyArrayList"] = arr;
      ObjectList1.DetailsCommandText = "MoreDetails";
   }
   arr = (ArrayList)Session["MyArrayList"];
   ObjectList1.DataSource = arr;
   ObjectList1.LabelField = "TaskName";
   ObjectList1.DataBind();
}

void SelectCommand(Object sender, ObjectListCommandEventArgs e)
{
   String myCommand;
   myCommand = e.CommandName;
   switch (myCommand)
   {
      // Remove selected item from the ObjectList using the array.
      case "Delete":
         int i = ObjectList1.SelectedIndex;
         arr.RemoveAt(i);
         Label2.Text = ObjectList1.Selection["TaskName"] + " deleted";
         Session["MyArrayList"] = arr;
         break;

      // Edit selected item (code below is non-functional).
      case "Edit":
         /* 
          { insert code to edit the item }
         */
         Label2.Text = ObjectList1.Selection["TaskName"] + " edit";
         break;
   }
}

void ShowTaskDetail(Object sender, ObjectListSelectEventArgs e)
{
   // Check for aguments that start with "ShowMore" so you can view 
   // the details of an item.
   if(e.SelectMore)
   {
      //Add or remove commands in the details view.
      if(e.ListItem["Editable"].ToString()=="No")
      {
         ObjectList1.Commands.RemoveAt(1);
      }
      if(e.ListItem["TaskName"].ToString()=="Tomorrow's work")
      {
         ObjectList1.Commands.RemoveAt(0);
      }
   }
   else
   {
      // If an argument for a selected item does not exist,
      // then do not show the details view.
      e.UseDefaultHandling = false;
   }
}
</script>

<mobile:Form runat=server id="Form1" >
   <mobile:ObjectList runat="server" id="ObjectList1" 
      OnItemCommand="SelectCommand" 
      OnItemSelect="ShowTaskDetail" >
      <Command Name="Delete" Text="Delete" />
      <Command Name="Edit" Text="Edit" />
   </mobile:ObjectList>
   <mobile:Label runat=server id="Label1" />
   <mobile:Label runat=server id="Label2" />
</mobile:Form>

Requirements

Namespace: System.Web.UI.MobileControls

Assembly: System.Web.Mobile