Back to Devexpress

ASPxGridView.ContextMenuItemClick Event

aspnet-devexpress-dot-web-dot-aspxgridview-16ad2059.md

latest5.1 KB
Original Source

ASPxGridView.ContextMenuItemClick Event

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

Declaration

csharp
public event ASPxGridViewContextMenuItemClickEventHandler ContextMenuItemClick
vb
Public Event ContextMenuItemClick As ASPxGridViewContextMenuItemClickEventHandler

Event Data

The ContextMenuItemClick event's data class is ASPxGridViewContextMenuItemClickEventArgs. 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.
MenuTypeGets the currently displayed context menu‘s type.

Remarks

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).

Example

csharp
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;
     }
}
vb
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

Context Menu

Context Menu

ContextMenuItemClick

Grid View

Online Demo: Grid - Context Menu

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace