asp.net.ph

GridView.AutoGenerateDeleteButton Property

System.Web.UI.WebControls Namespace   GridView Class


.NET Framework version 2.0

Sets or retrieves a value specifying whether a CommandField column with a Delete button for each data row is automatically added and displayed in a GridView control.

Syntax


Inline <asp:gridview autogeneratedeletebutton = true | false ... >
Script GridView.AutoGenerateDeleteButton [ = true | false ]

Property Value

This property accepts or returns only a boolean value: true if a CommandField column with a Delete button for each data row is automatically added and displayed; otherwise, false. Default value is false.

Remarks

Use this property to automatically create a CommandField column with a Delete button for each data row in a GridView control.

Clicking the Delete button for a row permanently removes that record from the data source.

Note that for the automatic deletion feature to work, the GridView must be bound to a data source control that is configured to delete data, meaning the DeleteCommand must have been properly set.

In addition, the DataKeyNames property must be set to specify the key field or fields of the data source that will identify the record to delete.

The GridView control raises the following events to which you can assign a custom action to perform when a row is deleted.

Event Description
RowDeleting Occurs when a row's Delete button is clicked, but before the GridView control deletes the record from the data source. This event is often used to cancel the deletion operation.
RowDeleted Occurs when a row's Delete button is clicked, but after the GridView control deletes the record from the data source. This event is often used to check the results of the delete operation.

Example

The below snippet demonstrates how to use the AutoGenerateDeleteButton property to enable the automatic deletion feature of a GridView control.

<asp:gridview id = "messagesGrid" runat = "server"
   datasourceid = "messages"
   datakeynames = "MessageID"
   autogeneratecolumns = "false"
   autogeneratedeletebutton ... >

WARNING: Deleting rows in a database table CANNOT BE UNDONE, which can result in serious data loss. In a real-world scenario, only the database administrator or an authorized user must be granted DELETE permission. The examples provided here are only for learning purposes.

GridView AutoGenerateDeleteButton Example
Run Sample | View Source
See Also

GridView Members   AutoGenerateEditButton   AutoGenerateSelectButton   Allowing Users to Delete Rows in a GridView Control Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph