C# – asp.net gridview command field and custom edit

asp.netcgridviewwebforms

I have a gridview that is serviced by a sqldatasource and I was just wondering how is it possible to have the Edit button do something other than put the gridview row in edit mode.

<asp:CommandField ShowSelectButton="True" ShowEditButton="true" ButtonType="Button" />

What I want to do is have a custom edit page/control that is loaded when you click Edit.
As opposed to just put the row in edit mode and turn the fields into editable textboxes.

Is something like that possible?

Best Answer

There are two options that come to my mind:

Use EditTemplates for your GridView fields
This will let you customize the look / content of each of the fields when they go into edit mode.

<Columns>
    <asp:TemplateField ...>
        <EditItemTemplate>
            <!-- child controls -->
        </EditItemTemplate>
        <ItemTemplate>
            <!-- child controls -->
        </ItemTemplate>
    </asp:TemplateField>
</Columns>

Handle the RowEditing event
You can handle the RowEditing event to do whatever manipulation on the Gridview that you want in repsonse to a "Edit" button in the row being clicked.