Share via


ObjectListShowCommandsEventArgs Class

Provides data for the ShowItemCommands event of an ObjectList control.

public class System.Web.UI.MobileControls.ObjectListShowCommandsEventArgs
   : System.EventArgs

Remarks

An instance of a ObjectListShowCommandsEventArgs object is automatically created and passed to the event handler for the ShowItemCommands event of an ObjectList control.

An inherited class or event handler can use this event to show commands unique to the item, by changing the collection of commands in the Commands property.

Example

The OnShowItemCommands event calls a user-defined event handler called SelectCommand. One of the parameters for this event handler is the ObjectListShowCommandsEventArgs object used in a conditional statement.

<%@ 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 object list.
   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

Requirements

Namespace: System.Mobile.Web.UI.MobileControls

Assembly: System.Web.Mobile