System.Web.UI.WebControls Namespace DetailsView Class
.NET Framework version 2.0
Sets or retrieves a value specifying whether the built-in control to delete a record is automatically added and displayed in a DetailsView control.
Inline |
<asp:detailsview autogeneratedeletebutton = true | false ... > |
Script |
DetailsView.AutoGenerateDeleteButton [ = true | false ] |
This property accepts or returns only a boolean value: true if the built-in controls to delete a record is automatically added and displayed; otherwise, false. Default value is false.
Use this property to specify whether the built-in control to delete a record are automatically added and displayed in a DetailsView control.
Note that for the automatic delete feature to work, the DetailsView 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 DetailsView control raises the following events to which you can assign a custom action to perform when a row is deleted.
Event |
Description |
ItemDeleteed |
Occurs when the Delete button is clicked, but after the DetailsView control deletes the record. This event is often used to check the results of the delete operation. |
ItemDeleting |
Occurs when the Delete button is clicked, but before the DetailsView control updates the record. This event is often used to cancel the delete operation. |
ModeChanged |
Occurs after the DetailsView control changes modes. |
ModeChanging |
Occurs before the DetailsView control changes modes. This event is often used to cancel the mode change. |
The following example demonstrates how to use the AutoGenerateDeleteButton property to display the built-in controls to delete a record in a DetailsView control.
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.
Show me
DetailsView Members AutoGenerateEditButton AutoGenerateInsertButton Allowing Users to Delete Rows in a DetailsView Control