This documentation is archived and is not being maintained.

ObjectList.ShowItemCommands Event

Occurs before the commands related to an item in an ObjectList are shown.

Namespace:  System.Web.UI.MobileControls
Assembly:  System.Web.Mobile (in System.Web.Mobile.dll)

public event ObjectListShowCommandsEventHandler ShowItemCommands
<asp:ObjectList OnShowItemCommands="ObjectListShowCommandsEventHandler" />

The event argument contains a reference to the item and to the collection of commands. An event handler can customize the collection according to the item. Applications can use the ShowItemCommands event to provide functionality equivalent to item-specific shortcut menus. Changes made to the collection of commands during this event are not persisted.

This event is called after the ItemSelect event is called. You can use this event to perform other tasks before showing the detail view. You can add, remove, or rearrange fields, depending on the item selected in the list view.

The following code example demonstrates how to use the ShowItemCommands event to remove an item from the ObjectListCommandCollection of the detail view of an ObjectList. The item to remove is selected in the list view.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information, see ASP.NET Web Page Code Model.

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    //System.Web.UI.MobileControls.ObjectListItem item; 
    //System.Web.UI.MobileControls.ObjectListItemCollection itemColl; 
    // Get the persisted array through postbacks.
    ArrayList arr = new ArrayList();
    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));

            // Persist the array in the Session object
            Session["MyArrayList"] = arr;

            // Associate and bind array to the  
            // ObjectList for each postback.
            ObjectList1.DataSource = arr;
            ObjectList1.LabelField = "TaskName";

    private void ItemCommand_Click(Object sender, 
        ObjectListCommandEventArgs e)
        // Get the array from the Session object
        arr = (ArrayList)Session["MyArrayList"];

        // Remove selected item from the ObjectLis 
        int i = ObjectList1.SelectedIndex;
        Session["MyArrayList"] = arr;

        // Re-Bind ObjectList to altered ArrayList.
        ObjectList1.DataSource = arr;
        ObjectList1.LabelField = "TaskName";
        ObjectList1.ViewMode = ObjectListViewMode.List;

    void ItemCommands_Show(Object sender, 
        ObjectListShowCommandsEventArgs e) 
        // Check conditions, and add or remove  
        // commands in the detail view. 
        if (e.ListItem["Editable"].Equals("No"))
        else if (ObjectList1.Commands.Count < 1)
                ObjectListCommand("Delete", "Delete"));

    private class Task
        private string _TaskName;
        private string _Editable;
        private int _Days;
        public Task(string TaskName, string Editable, int Days)
            _TaskName = TaskName;
            _Editable = Editable;
            _Days = Days;
        public string TaskName
        { get { return _TaskName; } }
        public string Editable
        { get { return _Editable; } }
        public int Days
        { get { return _Days; } }

<html xmlns="" >
    <mobile:Form runat="server" id="Form1" >
        <mobile:ObjectList runat="server" id="ObjectList1" 
            OnShowItemCommands="ItemCommands_Show" >
            <Command Name="Delete" Text="Delete" />
        <mobile:Label runat="server" id="Label1" />
        <mobile:Label runat="server" id="Label2" />

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1