Back to Devexpress

ASPxGridView.ContextMenuInitialize Event

aspnet-devexpress-dot-web-dot-aspxgridview-7dfbed26.md

latest3.2 KB
Original Source

ASPxGridView.ContextMenuInitialize Event

Occurs when the context menu is initialized.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxGridViewContextMenuInitializeEventHandler ContextMenuInitialize
vb
Public Event ContextMenuInitialize As ASPxGridViewContextMenuInitializeEventHandler

Event Data

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

PropertyDescription
ContextMenuGets the context menu.
MenuTypeGets the context menu type.

The event data class exposes the following methods:

MethodDescription
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):

aspx
<dx:ASPxGridView ID="Grid" OnContextMenuInitialize="Grid_ContextMenuInitialize"
    OnContextMenuItemClick="Grid_ContextMenuItemClick">
    <SettingsContextMenu>
        <RowMenuItemVisibility>
            <ExportMenu Visible="true" />
        </RowMenuItemVisibility>
    </SettingsContextMenu>
</dx:ASPxGridView>
csharp
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:

Online Demo

See Also

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace