Detailsview Update

The DetailsView control in ASP.NET generates a user interface that resembles the Form View of a Microsoft Access database. It is commonly used for updating or deleting the currently displayed record, as well as inserting new records. One of the primary uses of the DetailsView control is to facilitate the update of existing database records.

AutoGenerateEditButton property

To enable the update functionality, you can set the AutoGenerateEditButton property of the DetailsView control to True. This will automatically generate an edit button, allowing users to modify the displayed record. When the edit button is clicked, the DetailsView control enters edit mode, providing a user interface for editing the record's fields.


Furthermore, if you want the DetailsView control to initially appear in edit mode when loaded, you can set the DefaultMode property of the DetailsView control to the value Edit. This ensures that the control is initially displayed in an editable state, providing a streamlined experience for users who wish to update the record immediately upon viewing it.

detailsview-update Default.aspx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <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" AutoGenerateEditButton="true" /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>" SelectCommand="select * from [stores]" UpdateCommand="UPDATE [stores] SET stor_name=@stor_name,stor_address=@stor_address,city=@city, state=@state, zip=@zip WHERE stor_id=@stor_id" /> </div> </form> </body> </html>


By using the features and properties of the DetailsView control, developers can create efficient user interfaces for updating existing records in a database. Whether it's through the AutoGenerateEditButton property or the DefaultMode property, the DetailsView control provides flexibility in customizing the behavior and appearance of the edit functionality.