Back to Devexpress

ASPxClientGridView.ContextMenuItemClick Event

aspnet-js-aspxclientgridview-d024dcda.md

latest4.9 KB
Original Source

ASPxClientGridView.ContextMenuItemClick Event

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

Declaration

ts
ContextMenuItemClick: ASPxClientEvent<ASPxClientGridViewContextMenuItemClickEventHandler<ASPxClientGridView>>

Event Data

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

PropertyDescription
elementIndexReturns the processed element index.
handledSpecifies whether default context menu item click is handled manually, so no default processing is required.
itemGets the clicked context menu item.
objectTypeGets which grid element has been right clicked by the user.
processOnServerSpecifies whether or not to process the event on the server. Inherited from ASPxClientProcessingModeEventArgs.
usePostBackSpecifies 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.

aspx
<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>
csharp
protected void MyGridView_ContextMenuInitialize(object sender, ASPxGridViewContextMenuInitializeEventArgs e) {
     e.ContextMenu.Items.Add("Select All", "SelectAll");
     e.ContextMenu.Items.Add("Deselect All", "DeselectAll");
}
vb
Protected Sub MyGridView_ContextMenuInitialize(ByVal sender As Object, ByVal e As ASPxGridViewContextMenuInitializeEventArgs)
     e.ContextMenu.Items.Add("Select All", "SelectAll")
     e.ContextMenu.Items.Add("Deselect All", "DeselectAll")
End Sub

See Also

Context Menu

Context Menu

ContextMenuItemClick

Grid View

Online Demo: Grid - Context Menu

ASPxClientGridView Class

ASPxClientGridView Members