Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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 ShowItemCommands As ObjectListShowCommandsEventHandler
Dim instance As ObjectList
Dim handler As ObjectListShowCommandsEventHandler

AddHandler instance.ShowItemCommands, handler

/** @event */
public void add_ShowItemCommands (ObjectListShowCommandsEventHandler value)

/** @event */
public void remove_ShowItemCommands (ObjectListShowCommandsEventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

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="VB" 
    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.
    Private arr As New ArrayList()
    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not IsPostBack Then
            ' 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"
        End If
    End Sub

    Private Sub SelectCommand(ByVal sender As Object, _
         ByVal e As ObjectListCommandEventArgs)
        ' Get the array from the Session object
        arr = CType(Session("MyArrayList"), ArrayList)

        ' Remove selected item from the ObjectLis
        Dim i As Integer = ObjectList1.SelectedIndex
        Session("MyArrayList") = arr

        ' Re-Bind ObjectList to altered ArrayList.
        ObjectList1.DataSource = arr
        ObjectList1.LabelField = "TaskName"
        ObjectList1.ViewMode = ObjectListViewMode.List
    End Sub

    Public Sub ShowTaskDetail(ByVal sender As Object, _
        ByVal e As ObjectListShowCommandsEventArgs)

        ' Check conditions, and add or remove 
        ' commands in the detail view.
        If e.ListItem("Editable").Equals("No") Then
        ElseIf ObjectList1.Commands.Count < 1 Then
            ObjectList1.Commands.Add(New ObjectListCommand("Delete", "Delete"))
        End If
    End Sub

    Private Class Task
        Private _TaskName As String
        Private _Editable As String
        Private _Days As Integer
        Public Sub New(ByVal TaskName As String, _
            ByVal Editable As String, ByVal Days As Integer)

            _TaskName = TaskName
            _Editable = Editable
            _Days = Days
        End Sub
        Public ReadOnly Property TaskName() As String
                Return _TaskName
            End Get
        End Property
        Public ReadOnly Property Editable() As String
                Return _Editable
            End Get
        End Property
        Public ReadOnly Property Days() As Integer
                Return _Days
            End Get
        End Property
    End Class

<html xmlns="http:'www.w3.org/1999/xhtml" >
    <mobile:Form runat="server" id="Form1" >
        <mobile:ObjectList runat="server" id="ObjectList1" 
            OnItemCommand="SelectCommand" OnShowItemCommands="ShowTaskDetail" >
            <Command Name="Delete" Text="Delete" />
        <mobile:Label runat="server" id="Label1" />
        <mobile:Label runat="server" id="Label2" />

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1

Community Additions

© 2015 Microsoft