Skip to main content
A newer version of this page is available.
All docs
V19.2
Tab

ASPxGridView.FillContextMenuItems Event

Enables you to customize the context menu item collection.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v19.2.dll

Declaration

public event ASPxGridViewFillContextMenuItemsEventHandler FillContextMenuItems

Event Data

The FillContextMenuItems event's data class is ASPxGridViewContextMenuEventArgs. The following properties provide information specific to this event:

Property Description
Items Gets a collection of context menu items.
MenuType Gets the currently displayed context menu‘s type.

The event data class exposes the following methods:

Method Description
CreateItem(GridViewContextMenuCommand) Creates a new item with the specified command.
CreateItem(String, String) Creates a new item with the specified settings.

Remarks

The Grid context menu can be invoked by right-clicking a grid element. The FillContextMenuItems event is raised after default context menu items are created and before the context menu is shown; and enables you to customize the item collection.

You can use the event parameter’s properties to get the collection of context menu items (ASPxGridViewContextMenuEventArgs.Items) and the displayed menu type (ASPxGridViewContextMenuEventArgs.MenuType).

Example

The code sample below demonstrates how to provide the default grid context menu with two custom items. To add the items to the item collection, the ASPxGridView.FillContextMenuItems event is used. On the client-side, the ASPxClientGridView.ContextMenuItemClick event is handled to respond to a custom item click.

The image below demonstrates a context menu with the custom items.

ASPxGridView_ContextMenuExample

<dx:ASPxGridView ID="MyGridView" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource" ClientInstanceName="myGrid" KeyFieldName="ProductID" OnFillContextMenuItems="MyGridView_FillContextMenuItems">
     <ClientSideEvents ContextMenuItemClick="function(s, e) {
          switch(e.item.name) { 
               case 'SelectAll':
                    myGrid.SelectRows();
                    break;
               case 'DeselectAll':
                    myGrid.UnselectRows();
                    break;
          }
     }" />
     <Columns>
          ...
     </Columns>
     <SettingsBehavior AllowSelectByRowClick="True" />
     <SettingsContextMenu Enabled="True">
     </SettingsContextMenu>
</dx:ASPxGridView>
protected void MyGridView_FillContextMenuItems(object sender, ASPxGridViewContextMenuEventArgs e) {
     e.Items.Add("Select All", "SelectAll");
     e.Items.Add("Deselect All", "DeselectAll");
}
See Also