Formatting DetailsView control with style properties
We can customize appearance of the DetailsView control using its style properties. Alternatively, we can also use CSS styles to provide styles to DetailsView control.
Using CSS styles, we can change the font family and font size of the TextBox controls in the DetailsView control.
When the DetailsView control is in the edit mode, we use editrowstyle property to change the background color, font family and font size of the editable text boxes.
While the DetailsView control is in the Insert mode, the InsertRowStyle property is used to change the background color, font family and font size of the text boxes.
To change the style or background color of default buttons, we use CommandRowStyle property.
If we create a button using a CommandField element in the DetailsView control, we use the ItemStyle-CssClass property of CommandField to style the button.
The following style properties are used to customize the DetailsView control as shown below.
The below code demonstrates how to use different style properties to customize the appearance of the DetailsView control.
Using CSS styles, we can change the font family and font size of the TextBox controls in the DetailsView control.
When the DetailsView control is in the edit mode, we use editrowstyle property to change the background color, font family and font size of the editable text boxes.
While the DetailsView control is in the Insert mode, the InsertRowStyle property is used to change the background color, font family and font size of the text boxes.
To change the style or background color of default buttons, we use CommandRowStyle property.
If we create a button using a CommandField element in the DetailsView control, we use the ItemStyle-CssClass property of CommandField to style the button.
The following style properties are used to customize the DetailsView control as shown below.
HeaderStyle -Style used for header row RowStyle -Style used to display rows CommandRowStyle -Style used to display row that contains edit buttons FooterStyle -Style used for footer row PagerStyle -Style used to control the pager row appearance EmptyDataRowStyle-Style used to display row when data source does not return data items EditRowStyle -Style used to display rows when the DetailsView is in Edit
The below code demonstrates how to use different style properties to customize the appearance of the DetailsView control.
<asp:DetailsView ID="DetailsView1" runat="Server" ForeColor="#333333" Width="60%" DataSourceID="MyDataSource" AllowPaging="True" AutoGenerateRows="False" DataKeyNames="Code" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateInsertButton="True" > <FooterStyle Font-Bold="True" ForeColor="White" /> <CommandRowStyle BackColor="Beige" Font-Bold="True" /> <EditRowStyle BackColor="BlueViolet" /> <RowStyle BackColor="Chocolate" ForeColor="Black" /> <PagerStyle BackColor="Gold" ForeColor="White" HorizontalAlign="Center" /> <FieldHeaderStyle BackColor="Aquamarine" Font-Bold="True" /> <HeaderStyle BackColor="AliceBlue" Font-Bold="True" /> <AlternatingRowStyle BackColor="White" ForeColor="DarkGray" /> <InsertRowStyle BackColor="DeepSkyBlue" Font-Bold="True" ForeColor="DeepPink" /> <Fields> <asp:BoundField DataField="Code" HeaderText="Code" /> <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" 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
- DetailsView fields
- 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