DetailsView.Fields Property

Note: This property is new in the .NET Framework version 2.0.

Gets a collection of DataControlField objects that represent the explicitly declared row fields in a DetailsView control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public virtual DataControlFieldCollection Fields { get; }
/** @property */
public DataControlFieldCollection get_Fields ()

public function get Fields () : DataControlFieldCollection

Property Value

A DataControlFieldCollection that contains all explicitly declared row fields in the DetailsView control.

When you explicitly declare the row fields for a DetailsView control, these row fields are stored in the Fields property (collection). The Fields collection also allows you to programmatically manage the collection of explicitly declared rows.


Explicitly declared row fields can be used in combination with automatically generated row fields. When both are used, explicitly declared row fields are rendered first, followed by the automatically generated row fields. Automatically generated row fields are not added to the Fields collection.

Different row field types determine the behavior of the rows in the control. The following table shows the different row field types that can be used in the Fields collection.

Row field type



Displays the value of a field in a data source as text.


Displays a command button in the DetailsView control. This allows you to display a row with a custom button control, such as an Add or a Remove button.


Displays a check box in the DetailsView control. This row field type is commonly used to display fields with a Boolean value.


Displays built-in command buttons to perform edit, insert, or delete operations in the DetailsView control.


Displays the value of a field in a data source as a hyperlink. This row field type allows you to bind a second field to the hyperlink's URL.


Displays an image in the DetailsView control.


Displays user-defined content for a row in the DetailsView control according to a specified template. This row field type allows you to create a custom row field.

To explicitly declare the row fields for a DetailsView control, first set the AutoGenerateRows property to false. Next, add opening and closing <Fields> tags between the opening and closing tags of the DetailsView control. Finally, list the row fields that you want to include between the opening and closing <Fields> tags. The row fields are displayed in the DetailsView control in the order that the row fields appear in the Fields collection.

Although you can programmatically add row fields to the Fields collection, it is easier to list the row fields declaratively in the DetailsView control and then use the Visible property of each row field to show or hide the row field.

If the Visible property of a row field is set to false, the row is not displayed in the DetailsView control and the data for the row does not make a round trip to the client. If you want the data for a row that is not visible to make a round trip, add the field name to the DataKeyNames property.

The following code example demonstrates how to declaratively add row fields to the Fields collection of a DetailsView control.

<%@ Page language="C#" %>

<script runat="server">

    <form id="Form1" runat="server">
      <h3>DetailsView Fields Example</h3>
        <asp:detailsview id="CustomerDetailView"
           HeaderText="Company Name"/>
        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!-- from the web.config file.                            -->
        <asp:SqlDataSource ID="DetailsViewSource" runat="server" 
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID],
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"

          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0