Detailsview Delete
DetailsView generates a user interface similar to the Form View of a Microsoft Access database, and is typically used for updating/deleting any currently displayed record or for inserting new records. You can delete records with the DetailsView control by enabling its AutoGenerateDeleteButton property to true.
AutoGenerateDeleteButton="true"

When deleting records, you need to supply a value for the DetailsView controls DataKeyNames property. The following ASP.NET program shows how to delete a record from database using DetailsView control.
Default.aspx
<!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 id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView id="DetailsView1" DataSourceID="SqlDataSource1" DataKeyNames="stor_id"
AllowPaging ="true" Runat="server" AutoGenerateDeleteButton="true" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>"
SelectCommand="select * from [stores]"
DeleteCommand="DELETE [stores] WHERE stor_id=@stor_id" />
</div>
</form>
</body>
</html>
Related Topics