How to: Customize Controls for Editing in the GridView Web Server Control

When a row in the GridView control is put into edit mode, the row typically displays text or check boxes for individual columns of the data, where users can change the data. If you want to use different controls for editing, you can customize the GridView controls for edit mode. You do this by creating a template that defines the custom layout (text and controls) that you want to display in edit mode instead of the default controls. For more information, see ASP.NET Web Server Controls Templates.


To specify custom editing for a GridView column

  1. On the GridView Tasks shortcut menu, select the Enable Editing check box.


    The Enable Editing check box appears on the shortcut menu only if the data source control to which the GridView control is bound supports editing. For example, if the GridView control is bound to a SqlDataSource control, the UpdateCommand property must contain an SQL Update statement.

  2. On the shortcut menu, click Edit Columns.

    The Fields dialog box appears.

  3. Under Available fields, expand Bound Field to list the bound fields of the data source.

  4. Under Selected fields, select one bound field, click Convert this field into a TemplateField, and then click OK to close the Fields dialog box.

  5. On the shortcut menu, click Edit Templates.

    The GridView control switches to template-editing mode.

  6. On the shortcut menu, in the Display list, click EditItem Template.

    The GridView control displays the template editor for the EditItemTemplate property. This specifies the layout (text and controls) that will appear for that column when the row is in edit mode.

  7. From the Standard group in the Toolbox, drag a DropDownList control into the template.

    You will configure the DropDownList in the next procedure.

To populate a drop-down list for editing in a GridView column

  1. On the shortcut menu, in the Choose Data Source list, click New Data Source.

  2. In the Data Source Configuration Wizard, select the same data source that you used in the preceding procedure.

  3. Select data fields to display and corresponding values of the list from available fields in your data source, and then click OK.

  4. Press CTRL+F5 to run the page.

  5. Change a column in the grid to verify that the list appears.

See Also


Modifying Data in a GridView Web Server Control


GridView Web Server Control Overview