Data Binding in ASP.Net 2.0
 
The DetailsView Web Server Control
 
The DetailsView is a new data-bound control that enables you to view a single data record at a time .The DetailsView control presents the capability to display, edit, insert, or delete a single record at a time from its connected data source. The DetailsView control binds to a data source control, which in turn handles the tasks of connecting to a data store and returning the selected data. Data Binding to the DetailsView control is as simple as setting to the DataSourceID property. You can also bind to a data source in code. To allow editing, set the AutoGenerateEditButton property of the DetailsView to true.
 
Customizing User Interface of DetailsView Control
 
By default, the DetailsView control displays each field of a record on its own line. The user interface of the DetailsView control can be customized using data fields and using style properties such as the HeaderStyle, RowStyle, AlternatingRowStyle, CommandRowStyle, FooterStyle, PagerStyle, and EmptyDataRowStyle properties. The DetailsView control presents you additional customization through templates, which give you more control over the rendering of certain elements. You can define your own EmptyDataTemplate, HeaderTemplate, FooterTemplate, and PagerTemplate properties for the DetailsView control.
 
Displaying Data using DetailsView
 
You can bind data with the DetailsView control in following two ways:
 
1. Data binding using the DataSourceID property, which lets you to connect the DetailsView control to a data source control. It is recommended to use this approach as it allows the DetailsView control to take benefit of the capabilities of the data source control and to provide built-in functionality for updating and paging.

2. Using DataSource property you can bind data to various objects, including ADO.NET datasets and data readers. This need to write the code for any extra functionality such as updating and paging.
 
Binding of data source using the DataSourceID property, supports two-way data binding in the DetailsView control. In addition to the control displaying data, you can enable the control to automatically support insert, update, and delete operations on the bound data.
 
Inserting, Updating and Deleting Data using DetailsView
 
To insert the data using the DetailsView, simply add the AutoGenerateInsertButton attribute to the DetailsView control and set it to true. Then InsertCommand and corresponding InsertParameter elements to the SqlDataSource control as given below:
 
<asp:DetailsView id="MyDetailsView" runat="server" DataSourceId="MySource"
BorderColor=?red“AutoGenerateRows=?False? AutoGenerateInsertButton=?true?
DataKeyNames="employeeid" AutoGenerateEditButton="true">
</asp: DetailsView >
<asp:sqldatasource runat="server" id="MySource"
connectionstring="ConnectionString"
SelectCommand="Select Query String">
UpdateCommand="Update Query String">
InsertCommand="Update Query String">
FilterExpression=?RecordId=’@RecordId’?
<FilterParameters>
<asp: ControlParamter Name =?RecordId? ControlId=?MyDetailsView?
PropertyName=?SelectedValue?>
</asp: ControlParamter>
</FilterParameters>
<InsertParameters>
<asp: Parameter Type=?String? Name=RecordId>
...
...
</InsertParameters>
</asp:sqldatasource>
 
Similarly, by specifying the UpdateCommand or Delete Command attributes in the DetailsView Control and then providing the proper UpdateParameters and DeleteParameter elements, the update and delete of Data can easily performed.