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.

AutoGenerateEditButton="true"

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" "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" 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>

Conclusion

With the use of the attributes and the specifications of DetailsView control, it becomes possible to build the UI (user interface) for updating existing records in database that are faster and more efficient. It can be done through the AutoGenerateEditButton property as well as the DefaultMode property and provides flexibility in customization of the editing functionality, its operation and its look.