DetailsView fields
By default, the DetailsView control displays data in each field in a separate HTML table row. Each row corresponds to a field in the data source. We can bind the DetailsView control to the data source either by declaratively or programmatically.
By default, all the fields in the data source are displayed automatically because the AutoGenerateRows property value is set to true.
If we want more control over the display of fields in the detailsView control, first, we need to set the AutoGenerateRows property value to false. Next, we need to declare <Fields> element in the DetailsView control.
Using <Fields> element with the DetailsView control, we can define individual fields to be displayed by the control. The <Fields> element is similar to the element of the GridView control.
Within the <Fields> element we can declare the following different type of fields corresponding to the type of fields to be displayed by the DetailsView control.
The DetailsView control supports the following types of fields.
The below code demonstrates how to add BoundField element to the Fields section of the DetailsView control.
By default, all the fields in the data source are displayed automatically because the AutoGenerateRows property value is set to true.
If we want more control over the display of fields in the detailsView control, first, we need to set the AutoGenerateRows property value to false. Next, we need to declare <Fields> element in the DetailsView control.
Using <Fields> element with the DetailsView control, we can define individual fields to be displayed by the control. The <Fields> element is similar to the
Within the <Fields> element we can declare the following different type of fields corresponding to the type of fields to be displayed by the DetailsView control.
The DetailsView control supports the following types of fields.
BoundField - Displays the value of a data item as text CheckBoxField - Displays the value of a data item as check box CommandField - Displays links for editing, deleting and selecting ButtonField - Displays the value of a data item as a button HyperLinkField - Displays the value of a data item as link ImageField - Displays the value of a data item as image TemplateField - Enables customization of the appearance of a data item
The below code demonstrates how to add BoundField element to the Fields section of the DetailsView control.
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="true" DataKeyNames="Code" DataSourceID="MyDataSource" AutoGenerateRows="false" AutoGenerateInsertButton="true" AutoGenerateEditButton="true"> <Fields> <asp:BoundField DataField="Name" HeaderText="Name" /> <asp:BoundField DataField="description" HeaderText="description" /> </Fields> </asp:DetailsView> <asp:SqlDataSource ID="MyDataSource" ConnectionString="<%$Connectionstrings:ERPConnectionString%>" SelectCommand="SELECT * FROM Sample" UpdateCommand="Update SAMPLE SET Name=@Name,description=@description Where Code=@Code" DeleteCommand="Delete SAMPLE Where Code=@Code" InsertCommand="Insert SAMPLE(Code,Name,description) VALUES(@Code,@Name,@description)" runat="server"/>

DetailsView Articles
- Difference between DetailsView and FormView control
- DataBinding a DetailsView control
- GridView and DetailsView Master/Detail page using SqlDataSource control
- GridView and DetailsView master detail page using ObjectDataSource control
- DropDownList and GridView Master/Detail page using ObjectDataSource control
- DetailsView databound event
- DetailsView integer type conversion error?
- Using detailsview control datakeynames property
- How to get the datakey value in DetailsView control
- DetailsView autogeneraterows property
- Formatting DetailsView control with style properties
- Using Boundfields in DetailsView control
- Display message using EmptyDataTemplate in the DetailsView Control
- How to access DetailsView's fields programmatically
- Bind a DetailsView control with a DropDownList control
- Using Command buttons in DetailsView control
- Using Commandfield element in a DetailsView control
- Using buttonfield in a DetailsView control
Most Viewed
Azure Q & A
Azure Platform
Grid-View
GridView CommandField example
Details-View
GridView and DetailsView Master/Detail page using SqlDataSource control
POCO
POCO overview and advantages - POCO class, Entity Framework in Enterprise Applications
Entity Framework
Query entity data model using linq to entities
Array List
Difference between arraylist and list collection
Web Services
How to create a Web service using Visual Studio.net
Form-View
FormView DataBound Event
Object Oriented Programming
Calling base class constructor in C#
Linq
Convert a sequence to a generic list using ToList()method
ERP
ERP Software Development
Project Ideas
Project ideas for students
AccountingSoftware
Accounting Software
MVC
Creating an ASP.Net MVC 3 application
.Net
Using assemblies in .net applications
ASP .Net
How to implement form validation using ASP.Net 2.0 Validation Controls