ASP.NET Detailsview Binding

The DetailsView control in ASP.NET offers functionality similar to the GridView control, but with a distinct display style. While the GridView displays all records from its data source control in a tabular format, the DetailsView presents a single row from a data source at a time, rendering it as an HTML table.

DetailsView control

One common use case for the DetailsView control is in a master-details scenario. In this scenario, the selection of a record in a master control, such as a GridView, triggers the DetailsView to display the details of the selected record. This enables users to view and interact with specific details of a record without overwhelming the interface with all the data at once.


The DetailsView control supports both declarative and programmatic data binding. Declarative data binding allows developers to define the data source and configure the control's appearance and behavior directly in the markup, using data source controls like SqlDataSource or ObjectDataSource. Programmatic data binding, on the other hand, provides more flexibility by allowing developers to bind the DetailsView control dynamically in code, giving them greater control over the data retrieval and display process.

The following program shows how to bind a DetailsView from an ASP.NET application.

<!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" AllowPaging =true Runat="server" /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>" SelectCommand="select * from stores" /> </div> </form> </body> </html>


Through DetailsView control, the developers can easily develop the user interfaces in the form with which can be shown and edited the single record from the data source. It is angled towards providing master-detail scenarios, choosing from different data binding options and allowing a customizable table based layout that are quite essential in the development of impressive web applications. Whether used in a declarative format or as a programmer with the DetailsView, the control details balance offers as a clear and easy-to-use tool for maintaining and managing data.