Assembly: System.Web (in system.web.dll)
/** @property */ public boolean get_AutoGenerateDeleteButton () /** @property */ public void set_AutoGenerateDeleteButton (boolean value)
public function get AutoGenerateDeleteButton () : boolean public function set AutoGenerateDeleteButton (value : boolean)
Property Valuetrue to display the built-in control to delete the current record; otherwise, false. The default is false.
When a DetailsView control is bound to an object that inherits from DataSourceView and the CanDelete property returns true, the DetailsView control can take advantage of the data source control's capabilities and provide automatic deleting functionality.
When the AutoGenerateDeleteButton property is set to true, a CommandField row field with a Delete button is automatically displayed in the DetailsView control. Clicking the Delete button permanently removes that record from the data source.
You must also set the DataKeyNames property for the automatic deletion feature to work.
The DetailsView control provides several events that you can use to perform a custom action when a record is deleted. The following table lists the available events.
Occurs when the Delete button is clicked, but after the DetailsView control deletes the record from the data source. This event is often used to check the results of the delete operation.
Occurs when the Delete button is clicked, but before the DetailsView control deletes the record from the data source. This event is often used to cancel the delete operation.
The value of AutoGenerateDeleteButton is stored in view state.
The following code example demonstrates how to use the AutoGenerateDeleteButton property to display the built-in control to delete the current record.
<%@ Page language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>DetailsView AutoGenerateDeleteButton Example</title> </head> <body> <form id="Form1" runat="server"> <h3>DetailsView AutoGenerateDeleteButton Example</h3> <asp:detailsview id="CustomersDetailView" datasourceid="DetailsViewSource" datakeynames="CustomerID" autogeneratedeletebutton="true" autogeneraterows="true" allowpaging="true" runat="server"> <headerstyle backcolor="Navy" forecolor="White"/> </asp:detailsview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the web.config file. --> <asp:SqlDataSource ID="DetailsViewSource" runat="server" ConnectionString= "<%$ ConnectionStrings:NorthWindConnectionString%>" InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)" SelectCommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"> </asp:SqlDataSource> </form> </body> </html>