ObjectListCommandEventArgs Class
Provides information data for the ItemCommand event of an ObjectList control.
public class System.Web.UI.MobileControls.ObjectListCommandEventArgs :
System.Web.UI.WebControls.CommandEventArgs
Example
In this example, the OnItemCommand event calls a user-defined function AskForBook
. One of the arguments is the ObjectListCommandEventArgs
argument. You can use the properties of this argument to select the text to display in a label.
<%@ 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>
Requirements
Namespace: System.Web.UI.MobileControls
Assembly: System.Web.Mobile