Skip to content

Create a custom Edit button and specify its action based on the row's visible index.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-web-forms-grid-specify-custom-button-action-for-grid-rows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to specify a custom button action for particular grid rows

This example demonstrates how to create a custom Edit button and specify its action based on the row's visible index.

customEditButton

Overview

Follow the steps below:

  1. 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>
  2. 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);
    }

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Create a custom Edit button and specify its action based on the row's visible index.

Topics

Resources

License

Stars

Watchers

Forks