Skip to main content

ASPxClientGridView.ContextMenuItemClick Event

Fires on the client side when a context menu item has been clicked.

Declaration

ContextMenuItemClick: ASPxClientEvent<ASPxClientGridViewContextMenuItemClickEventHandler<ASPxClientGridView>>

Event Data

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

Property Description
elementIndex Returns the processed element index.
handled Specifies whether default context menu item click is handled manually, so no default processing is required.
item Gets the clicked context menu item.
objectType Gets which grid element has been right clicked by the user.
processOnServer Specifies whether or not to process the event on the server. Inherited from ASPxClientProcessingModeEventArgs.
usePostBack Specifies whether a postback or a callback is used to finally process the event on the server side.

Remarks

Handle the ContextMenuItemClick event to perform specific actions on the client side when a context menu item is clicked. Note that this event fires immediately after the left mouse button is released. If the button is released when the mouse pointer is not over a context menu item, the event doesn’t fire.

On the server side, handle the ASPxGridView.ContextMenuItemClick event to respond to a context menu item click. To allow the grid to raise the server-side event, set the processOnServer argument property to true in the client-side ContextMenuTemClick event handler.

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 ContextMenuInitialize 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" OnContextMenuInitialize="MyGridView_ContextMenuInitialize">
     <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_ContextMenuInitialize(object sender, ASPxGridViewContextMenuInitializeEventArgs e) {
     e.ContextMenu.Items.Add("Select All", "SelectAll");
     e.ContextMenu.Items.Add("Deselect All", "DeselectAll");
}
See Also