Classe ObjectListCommandEventArgs

Rende disponibili informazioni sull'evento ItemCommand di un controllo ObjectList.

public class System.Web.UI.MobileControls.ObjectListCommandEventArgs : 
   System.Web.UI.WebControls.CommandEventArgs

Esempio

In questo esempio, l'evento OnItemCommand chiama la funzione AskForBook definita dall'utente. Uno degli argomenti è ObjectListCommandEventArgs. Per selezionare il testo da visualizzare in un'etichetta, è possibile utilizzare le proprietà dell'argomento.

<%@ 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 auto-generation.
   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>

Requisiti

Spazio dei nomi: System.Web.UI.MobileControls

Assembly: System.Web.Mobile