Partager via


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

The GridView control supports a delete mode in which users can delete the current row from the data source. You can add delete capability to the GridView control without writing any code. You can configure the GridView control to display a Delete button in each row. When users click the button, the row is deleted from the data source and the grid is redisplayed.

Note

Deleting data using the GridView control is permanent; you cannot undo the deletion.

Procedures

To enable default deleting using the smart panel

  1. Right-click the GridView control and click Show Smart Tag.

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

    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 deleting. For example, if the GridView control is bound to a SqlDataSource control, the SqlDataSource control's DeleteQuery property must contain a SQL Delete statement.

Alternatively, you can set a GridView control property.

To enable deleting using the AutoGenerateDeleteButton property

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

    -or-

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

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

See Also

Concepts

Modifying Data in a GridView Web Server Control

Reference

GridView Web Server Control Overview