Share via


ObjectListCommand Class

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

public class System.Web.UI.MobileControls.ObjectListCommand : 
   System.Object

Remarks

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

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

Example

This example shows how to create instances of ObjectListCommand objects while a page loads. The user-defined function, SelectCommand, determines which ObjectListCommand to add to the object list.

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

<script Language="c#" runat="server">

System.Web.UI.MobileControls.ObjectListCommand Command1;
System.Web.UI.MobileControls.ObjectListCommand Command2;

class Book
{
   private String _BookName, _Author, _InStock;
   
   public Book(String BookName, String Author, String InStock) 
   { 
       _BookName = BookName; 
       _Author = Author;
       _InStock = InStock;
   }    

   public String BookName { get { return _BookName; } }
   public String Author { get { return _Author; } }
   public String InStock { get { return _InStock; } }
}

public void Page_Load(Object sender, EventArgs e)
{
   // Create and fill array.
   ArrayList arr = new ArrayList();
   arr.Add (new Book ("Sushi, Anyone?", "O'Leary", "Yes"));
   arr.Add (new Book ("Secrets of Silicon Valley", "Dull", "No"));
   arr.Add (new Book ("Net Etiquette", "Locksley", "Yes"));
   arr.Add (new Book ("The Gourmet Microwave", "Ringer", "No"));

   // Associate and bind array to the ObjectList.
   ObjectList1.DataSource = arr;
   ObjectList1.DataBind ();

   // Override autogeneration.
   ObjectList1.LabelField = "BookName";

   Command1 = new System.Web.UI.MobileControls.ObjectListCommand
      ("CheckOut", "CheckOut");
   Command2 = new System.Web.UI.MobileControls.ObjectListCommand
      ("Reserve", "Reserve");
}

void SelectCommand(Object sender, 
   ObjectListShowCommandsEventArgs e)
{
   if ( ((Book)e.ListItem.DataItem).InStock == "Yes" )
   {
      ObjectList1.Commands.Add(Command1);
   }
   else
   {
      ObjectList1.Commands.Add(Command2);
   }  
}

void AskForBook(Object sender, ObjectListCommandEventArgs e)
{
   if (e.CommandName == "CheckOut")
   {
      Label1.Text = "You have checked out this book at " 
                  + System.DateTime.Now;
   }
   else if (e.CommandName == "Reserve")
   {
      Label1.Text = "You have reserved this book at " 
                  + System.DateTime.Now;
   }
}
</script>

<mobile:Form runat="server" id="Form1" >
    <mobile:ObjectList runat="server" id="ObjectList1" 
       OnShowItemCommands="SelectCommand" 
       OnItemCommand="AskForBook">
    </mobile:ObjectList>
    <mobile:Label runat="server" id="Label1" />
</mobile:Form>

Requirements

Namespace: System.Web.UI.MobileControls

Assembly: System.Web.Mobile