This example demonstrates how to create a custom Edit button and specify its action based on the row's visible index.
Follow the steps below:
-
Create the Grid View control and bind it to a data source. Add a GridViewCommandColumn and use the CustomButtons property to create a custom Edit button.
<asp:AccessDataSource ID="ads" runat="server" DataFile="~/App_Data/NorthWind.mdb" SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]"> </asp:AccessDataSource> <dx:ASPxGridView ID="gv" ClientInstanceName="gv" runat="server" AutoGenerateColumns="False" KeyFieldName="CategoryID" DataSourceID="ads" ...> <ClientSideEvents CustomButtonClick="gv_OnCustomButtonClick" /> <Columns> <dx:GridViewCommandColumn VisibleIndex="0"> <CustomButtons> <dx:GridViewCommandColumnCustomButton ID="EditBnt" Text="Edit" /> </CustomButtons> </dx:GridViewCommandColumn> <!-- ... --> </Columns> <!-- ... --> </dx:ASPxGridView>
-
Handle the grid's client-side CustomButtonClick event. Use the row's visible index to indicate whether the row is odd or even. Call the grid's StartEditRow method to start editing even rows. For odd rows, specify an alert message.
function gv_OnCustomButtonClick(s, e) { if (e.visibleIndex % 2 === 0) alert("You cannot edit this row!"); else s.StartEditRow(e.visibleIndex); }
- Default.aspx (VB: Default.aspx)
(you will be redirected to DevExpress.com to submit your response)