Skip to main content
All docs
V24.1
Tab

ASPxGridView.ContextMenuInitialize Event

Occurs when the context menu is initialized.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public event ASPxGridViewContextMenuInitializeEventHandler ContextMenuInitialize

Event Data

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

Property Description
ContextMenu Gets the context menu.
MenuType Gets the context menu type.

The event data class exposes the following methods:

Method Description
CreateItem(GridViewContextMenuCommand) Creates a new context menu item.
CreateItem(String, String) Creates a new context menu item.

Remarks

You can use the ContextMenuInitialize event to customize the context menu when it is initialized.

The following example illustrates how to add a new context menu item when a user right clicks a grid row (MenuType):

<dx:ASPxGridView ID="Grid" OnContextMenuInitialize="Grid_ContextMenuInitialize"
    OnContextMenuItemClick="Grid_ContextMenuItemClick">
    <SettingsContextMenu>
        <RowMenuItemVisibility>
            <ExportMenu Visible="true" />
        </RowMenuItemVisibility>
    </SettingsContextMenu>
</dx:ASPxGridView>
protected void Grid_ContextMenuInitialize(object sender, ASPxGridViewContextMenuInitializeEventArgs e) {
    if(e.MenuType == GridViewContextMenuType.Rows) {
        var exportMenuItem = e.ContextMenu.Items.FindByCommand(GridViewContextMenuCommand.ExportMenu);
        exportMenuItem.Items.Add("Custom export to XLS(WYSIWYG)", "CustomExportToXLS").Image.IconID = "export_exporttoxls_16x16";
    }
}

Result:

GridView - ContextMenuInitialize Event

Online Demo

See Also