Udostępnij za pośrednictwem


How to: Enable Default Editing in the GridView Web Server Control

In addition to displaying data, the GridView control supports an edit mode in which users can change the contents of an individual row. You can configure the GridView control to display an Edit button in each row. When users click the button, the row is redisplayed in edit mode, with the data available in editable controls such as TextBox and CheckBox controls. The Edit button becomes an Update or Save button, and when users click it, the updated row is written back to the data store. You can add editing capability to the GridView control without writing any code.

Procedures

The following procedure illustrates how to enable default editing in the GridView control.

To enable default editing using the smart tag

  1. In Design view, right-click the GridView control and click Show Smart Tag.

  2. In the smart tag panel, select Enable Editing.

    Note

    The Enable Editing check box appears in the smart tag panel only if the data source control to which GridView control is bound supports editing. For example, if the GridView control is bound to a SqlDataSource control, the SqlDataSource control's UpdateQuery property must contain a SQL Update statement.

Alternatively, you can set a GridView control property.

To enable default editing using the AutoGenerateEditButton property

  • Select the GridView control, and in the Properties window, set AutoGenerateEditButton to true.

    -Or-

  • In Source view, in the <asp:GridView> element, set AutoGenerateEditButton to true, as in the following example:

    <asp:GridView Runat="server" ID="GridView1" 
      AutoGenerateEditButton="true" />
    

See Also

Concepts

Modifying Data in a GridView Web Server Control

Reference

GridView Web Server Control Overview