Assembly: System.Web (in System.Web.dll)
<PersistenceModeAttribute(PersistenceMode.InnerProperty)> Public Overridable ReadOnly Property Fields As DataControlFieldCollection
Property ValueType: System.Web.UI.WebControls.DataControlFieldCollection
When you explicitly declare the row fields for a DetailsView control, these row fields are stored in the property (collection). The 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 thecollection.
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 thecollection.
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 collection.
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 DetailsView control.collection of a
<%@ Page language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>DetailsView Fields Example</title> </head> <body> <form id="Form1" runat="server"> <h3>DetailsView Fields Example</h3> <asp:detailsview id="CustomerDetailView" datasourceid="DetailsViewSource" datakeynames="CustomerID" AutoGenerateRows="false" allowpaging="true" runat="server"> <Fields> <asp:BoundField DataField="CompanyName" HeaderText="Company Name"/> <asp:BoundField DataField="City" HeaderText="City"/> </Fields> </asp:detailsview> <!-- 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" ConnectionString= "<%$ 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 [Customers]"> </asp:SqlDataSource> </form> </body> </html>
Available since 2.0