This documentation is archived and is not being maintained.

DynamicField Class

Updated: July 2008

Represents a data field that is displayed in a data-bound control that uses ASP.NET Dynamic Data features.

Namespace:  System.Web.DynamicData
Assembly:  System.Web.DynamicData (in System.Web.DynamicData.dll)

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class DynamicField : DataControlField, 
	IAttributeAccessor, IFieldFormattingOptions

The DynamicField class is used by data-bound controls, such as GridView and DetailsView, to display a field value that uses ASP.NET Dynamic Data features in custom pages.

The DynamicField class provides functionality that resembles that of the BoundField class. However, because a DynamicField object is used in Dynamic Data applications, you can take advantage of the following Dynamic Data features:

  • Automatically rendering the proper control for a field by using field templates, based on the data type. The field templates can be globally modified for the entire application.

  • Providing built-in data validation based on the database schema. You can also add validation types by customizing the data model.

  • Customizing data rendering for individual fields by using attributes in the data model or by using the UIHint property.

The DynamicField object renders each field by using a DynamicControl control. To specify the data field to display in a DynamicField object, set the DataField property to the field name. You can apply a custom formatting string to the field value by setting the DataFormatString property. By default the formatting string is applied to field values only when the data-bound control is in read-only mode. To apply the formatting string to values displayed while the data-bound control is in edit mode, set the ApplyFormatInEditMode property to true. If a field value is null, you can display a custom caption by setting the NullDisplayText property. The DynamicField object can also automatically convert empty string ("") field values to null values by setting the ConvertEmptyStringToNull property to true.

See a run-time code example of this feature: Run.

The following example demonstrates how to use the DynamicField object in a GridView control to display and edit values from a database table.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">
  protected void Page_Init(object sender, EventArgs e)

<html xmlns="">
<head runat="server">
  <title>DynamicField Sample</title>
  <link href="~/Site.css" rel="stylesheet" type="text/css" />
  <form id="form1" runat="server">

      <h2><%= CustomersDataSource.TableName%> Table</h2>

      <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        AutoLoadForeignKeys="true" />

      <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true" 
        HeaderText="List of validation errors"  />
      <asp:DynamicValidator runat="server" ID="DynamicValidator1"
        ControlToValidate="CustomersGridView" Display="None" />

      <asp:GridView ID="CustomersGridView" runat="server"
          <asp:DynamicField DataField="CustomerID" />
          <asp:DynamicField DataField="FirstName" />
          <asp:DynamicField DataField="LastName" />

      <!-- This example uses Microsoft SQL Server and connects   -->
      <!-- to the AdventureWorksLT sample database.              -->
      <asp:LinqDataSource ID="CustomersDataSource" runat="server" 
        EnableDelete="true" >


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5 SP1




July 2008

Added topic for new class.

SP1 feature change.