aspnet-devexpress-dot-web-dot-aspxgridview-16ad2059.md
Fires on the server side when a context menu item has been clicked.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public event ASPxGridViewContextMenuItemClickEventHandler ContextMenuItemClick
Public Event ContextMenuItemClick As ASPxGridViewContextMenuItemClickEventHandler
The ContextMenuItemClick event's data class is ASPxGridViewContextMenuItemClickEventArgs. 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. |
| MenuType | Gets the currently displayed context menu‘s type. |
To allow the grid to raise the server-side ContextMenuItemClick event, handle the client-side ContextMenuItemClick event and set the processOnServer argument property to true.
Handle the ContextMenuItemClick event to perform specific actions 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.
If you want to perform a custom action on a default context menu item click, set the ASPxGridViewContextMenuItemClickEventArgs.Handled property to true to prevent default actions.
You can use the event parameter’s properties to identify the clicked item (ASPxGridViewContextMenuItemClickEventArgs.Item), the menu type (ASPxGridViewContextMenuItemClickEventArgs.MenuType), and determine the index of the right-clicked row or column (ASPxGridViewContextMenuItemClickEventArgs.ElementIndex).
protected void MyGridView_ContextMenuInitialize(object sender, ASPxGridViewContextMenuInitializeEventArgs e) {
e.ContextMenu.Items.Add("PDF", "ExportToPDF");
e.ContextMenu.Items.Add("XLS", "ExportToXLS");
}
protected void Grid_ContextMenuItemClick(object sender, ASPxGridViewContextMenuItemClickEventArgs e) {
switch(e.Item.Name) {
case "ExportToPDF":
GridExporter.WritePdfToResponse();
break;
case "ExportToXLS":
GridExporter.WriteXlsToResponse();
break;
}
}
Protected Sub MyGridView_ContextMenuInitialize(ByVal sender As Object, ByVal e As ASPxGridViewContextMenuInitializeEventArgs)
e.ContextMenu.Items.Add("PDF", "ExportToPDF")
e.ContextMenu.Items.Add("XLS", "ExportToXLS")
End Sub
Protected Sub Grid_ContextMenuItemClick(ByVal sender As Object, ByVal e As ASPxGridViewContextMenuItemClickEventArgs)
Select Case e.Item.Name
Case "ExportToPDF"
GridExporter.WritePdfToResponse()
Case "ExportToXLS"
GridExporter.WriteXlsToResponse()
End Select
End Sub
See Also