Skip to main content
Tab

ASPxGridView.CustomButtonInitialize Event

Enables you to initialize custom command buttons.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.2.dll

Declaration

public event ASPxGridViewCustomButtonEventHandler CustomButtonInitialize

Event Data

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

Property Description
ButtonID Gets the processed custom button’s identifier. Inherited from ASPxGridCustomCommandButtonEventArgs.
CellType Gets a value that specifies in which row a custom button is displayed.
Column Gets a command column which owns the processed custom button.
Enabled Gets or sets a value that specifies whether the processed custom button is enabled. Inherited from ASPxGridCustomCommandButtonEventArgs.
Image Gets the settings of an image displayed within the processed custom button. Inherited from ASPxGridCustomCommandButtonEventArgs.
IsEditingRow Gets whether a custom button is displayed within the data row currently being edited.
RenderMode Specifies the processed custom command button’s render mode. Inherited from ASPxGridCustomCommandButtonEventArgs.
Styles Gets the processed custom button’s style. Inherited from ASPxGridCustomCommandButtonEventArgs.
Text Gets or sets the processed custom button’s text. Inherited from ASPxGridCustomCommandButtonEventArgs.
Visible Gets or sets whether the processed custom button is visible. Inherited from ASPxGridCustomCommandButtonEventArgs.
VisibleIndex Gets the visible index of a data item (row, card or record) which contains the processed custom button. Inherited from ASPxGridCustomCommandButtonEventArgs.

Remarks

The CustomButtonInitialize event fires for each custom command button, and allows you to initialize it. For instance, you can handle this event to hide individual buttons.

The event parameter’s properties allow you to identify the button, row, the type of a cell which contains the processed button, etc.

To initialize individual built-in command buttons (edit, new, delete, etc.), handle the ASPxGridView.CommandButtonInitialize event.

In the CustomButtonInitialize event, you can change the style of the selection check box.

Note

If you call the GetRowValues method in the CustomButtonInitialize event handler, you should take into account the specific behavior described in the ASPxGridView.GetRowValues topic.

Example

The following example demonstrates how to specify the properties of the command and custom command buttons in the CommandButtonInitialize and CustomButtonInitialize events. The visibleIndex argument property and a custom criteria determine the button visibility.

View Example: How to specify the settings of built-in and custom command buttons based on a condition

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1"
    KeyFieldName="ProductID" OnCommandButtonInitialize="ASPxGridView1_CommandButtonInitialize"
    OnCustomButtonInitialize="ASPxGridView1_CustomButtonInitialize">
    <ClientSideEvents CustomButtonClick="OnCustomButtonClick" />
    <Columns>
        <dx:GridViewCommandColumn VisibleIndex="0" ShowEditButton="True" ShowNewButton="True" ShowDeleteButton="True">
            <CustomButtons>
                <dx:GridViewCommandColumnCustomButton ID="btnCustom" Text="CustomButton">
                </dx:GridViewCommandColumnCustomButton>
            </CustomButtons>
        </dx:GridViewCommandColumn>
        <!-- ... -->
    </Columns>
</dx:ASPxGridView>
function OnCustomButtonClick(s, e) {
    alert('keyValue = ' + s.GetRowKey(e.visibleIndex));
}
protected void ASPxGridView1_CommandButtonInitialize(object sender, ASPxGridViewCommandButtonEventArgs e) {
    if (e.VisibleIndex == -1) return;

    switch (e.ButtonType) {
        case ColumnCommandButtonType.Edit:
            e.Visible = EditButtonVisibleCriteria((ASPxGridView)sender, e.VisibleIndex);
            break;
        case ColumnCommandButtonType.Delete:
            e.Visible = DeleteButtonVisibleCriteria((ASPxGridView)sender, e.VisibleIndex);
            break;
    }
}
protected void ASPxGridView1_CustomButtonInitialize(object sender, ASPxGridViewCustomButtonEventArgs e) {
    if (e.VisibleIndex == -1) return;

    if (e.ButtonID == "btnCustom" && e.VisibleIndex % 2 != 0)
        e.Visible = DefaultBoolean.False;
}
// ...
private bool EditButtonVisibleCriteria(ASPxGridView grid, int visibleIndex) {
    object row = grid.GetRow(visibleIndex);
    return ((DataRowView)row)["ProductName"].ToString().Contains("a");
}
private bool DeleteButtonVisibleCriteria(ASPxGridView grid, int visibleIndex) {
    object row = grid.GetRow(visibleIndex);
    return ((DataRowView)row)["ProductName"].ToString().Contains("b");
}
See Also