asp.net.ph

Skip Navigation Links

Specifying Row Format in a DetailsView Control

Controls You Can Use on Web Forms   ASP.NET Data Controls   DetailsView Control


The DetailsView Web server control includes properties for customizing the format of items in the control. Formatting is applied in the order listed below:

  • styles that apply to the DetailsView control as a whole
  • styles that apply to each row type
  • styles that apply to each field type

To set the format for the DetailsView as a whole

  • Set the properties within the opening tag of the DetailsView control.
    <asp:detailsview id="detailsView" runat="server"
       width="90%" 
       cellpadding=5
       font-size="9pt"
       ... />

To set the format for individual row types

  • Set the properties within the opening tag of the appropriate Style object in the DetailsView.
    <asp:detailsview id="detailsView" runat="server"
       cellpadding=5
       font-size="9pt">
    
       <headerstyle backcolor="maroon"
          forecolor="khaki" />
    
       <rowstyle backcolor="khaki"
          borderstyle="outset"
          borderwidth="1px"
          horizontalalign="center" />
    
       <insertrowstyle backcolor="lightgreen"
          borderstyle="inset"
          borderwidth="1px"
          horizontalalign="center" />
    
    </asp:detailsview>

To set the format for individual field types

  • Set the properties within the opening tag of the appropriate field type in the DetailsView.
    <fields>
    
       <asp:hyperlinkfield headertext="Title"
          ...
          itemstyle-backcolor="navy"
          itemstyle-forecolor="lime"
    
       <asp:boundfield headertext="Price"
          ...
          itemstyle-horizontalalign="right" />
    
       <asp:buttonfield text="Add"
          itemstyle-backcolor="maroon"
          itemstyle-forecolor="khaki"
          commandname="AddToCart"  />
    
    </fields>

Changing the row and field style settings override the settings made for the entire control.

Style properties can also be set programmatically. For more information, see DetailsView in the class library.

See Also

Adding DetailsView Controls to a Web Forms Page   Specifying Paging Behavior in a DetailsView Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note