ASPxGridView.CustomButtonInitialize Event
Enables you to initialize custom command buttons.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v18.1.dll
Declaration
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 is raised for each custom command button, and enables 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.
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.
Note
It is impossible to change the style of the selection checkbox using the CustomButtonInitialize event.
Example
The example demonstrates how to specify the CommandButtons and Custom CommandButtons properties by handling the CommandButtonInitialize and CustomButtonInitialize events. The DataRows' VisibleIndex property and criteria set based on field values are used to determine the buttons' visibility.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-specify-built-in-and-custom-command-buttons-properties-based-on-custom-criteria-e3028
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v15.1, Version=15.1.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
function OnCustomButtonClick(s, e) {
alert('keyValue = ' + s.GetRowKey(e.visibleIndex));
}
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<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>
<dx:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice] FROM [Products]"
DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = ?" InsertCommand="INSERT INTO [Products] ([ProductName], [UnitPrice]) VALUES (?, ?)"
UpdateCommand="UPDATE [Products] SET [ProductName] = ?, [UnitPrice] = ? WHERE [ProductID] = ?"
OnUpdating="AccessDataSource1_Modifying" OnDeleting="AccessDataSource1_Modifying"
OnInserting="AccessDataSource1_Modifying">
<DeleteParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
</InsertParameters>
</asp:AccessDataSource>
</div>
</form>
</body>
</html>