1 out of 2 rated this helpful - Rate this topic

DynamicField Class

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

System.Object
  System.Web.UI.WebControls.DataControlField
    System.Web.DynamicData.DynamicField

Namespace:  System.Web.DynamicData
Assembly:  System.Web.DynamicData (in System.Web.DynamicData.dll)
public class DynamicField : DataControlField, 
	IAttributeAccessor, IFieldFormattingOptions

The DynamicField type exposes the following members.

  Name Description
Public method DynamicField Initializes a new instance of the DynamicField class.
Top
  Name Description
Public property AccessibleHeaderText Gets or sets text that is rendered as the AbbreviatedText property value in some controls. (Inherited from DataControlField.)
Public property ApplyFormatInEditMode Gets or sets a value that indicates whether the formatted string that is specified by the DataFormatString property is applied to field value when the data field is in edit mode.
Protected property Column Gets the MetaColumn object that this DynamicField object is associated with.
Protected property Control Gets a reference to the data control that the DataControlField object is associated with. (Inherited from DataControlField.)
Public property ControlStyle Gets the style of any Web server controls contained by the DataControlField object. (Inherited from DataControlField.)
Public property ConvertEmptyStringToNull Gets or sets a value that indicates whether empty string values ("") are automatically converted to null values when the data field is updated in the data source.
Public property DataField Gets or sets the name of the data field to bind the DynamicField object to.
Public property DataFormatString Gets or sets the string that specifies the display format for the value of the data field.
Protected property DesignMode Gets a value indicating whether a data control field is currently viewed in a design-time environment. (Inherited from DataControlField.)
Public property FooterStyle Gets or sets the style of the footer of the data control field. (Inherited from DataControlField.)
Public property FooterText Gets or sets the text that is displayed in the footer item of a data control field. (Inherited from DataControlField.)
Public property HeaderImageUrl Gets or sets the URL of an image that is displayed in the header item of a data control field. (Inherited from DataControlField.)
Public property HeaderStyle Gets or sets the style of the header of the data control field. (Inherited from DataControlField.)
Public property HeaderText Gets or sets the text that is displayed in the header of the data-bound control that contains the DynamicField object. (Overrides DataControlField.HeaderText.)
Public property HtmlEncode Gets or sets a value that indicates whether data field values are HTML-encoded before they are displayed in a DynamicField object.
Public property InsertVisible Gets a value indicating whether the DataControlField object is visible when its parent data-bound control is in insert mode. (Inherited from DataControlField.)
Protected property IsTrackingViewState Gets a value indicating whether the DataControlField object is saving changes to its view state. (Inherited from DataControlField.)
Public property ItemStyle Gets the style of any text-based content displayed by a data control field. (Inherited from DataControlField.)
Public property NullDisplayText Gets or sets the caption that is displayed for a data field when the field value is null.
Public property ReadOnly Gets the read-only state of the dynamic field.
Public property ShowHeader Gets or sets a value indicating whether the header item of a data control field is rendered. (Inherited from DataControlField.)
Public property SortExpression Gets or sets the sort expression that is used when the data field is used to sort the data source by. (Overrides DataControlField.SortExpression.)
Public property UIHint Gets or sets the field template to use for displaying the data field.
Public property ValidationGroup Gets the ValidationGroup object that this DynamicField object is associated with.
Protected property ViewState Gets a dictionary of state information that allows you to save and restore the view state of a DataControlField object across multiple requests for the same page. (Inherited from DataControlField.)
Public property Visible Gets or sets a value indicating whether a data control field is rendered. (Inherited from DataControlField.)
Top
  Name Description
Protected method CloneField Infrastructure. Creates a duplicate copy of the current DataControlField-derived object. (Inherited from DataControlField.)
Protected method ConfigureDynamicControl Provides a mechanism to modify a DynamicControl object that was created by the InitializeCell method.
Protected method CopyProperties Copies the properties of the current DynamicField object to the specified DataControlField object. (Overrides DataControlField.CopyProperties(DataControlField).)
Protected method CreateDynamicControl Provides a mechanism for classes that derive from DynamicField to override how a DynamicControl object is created.
Protected method CreateField Creates and returns a new instance of the DynamicField class. (Overrides DataControlField.CreateField().)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public method ExtractValuesFromCell Extracts the value of the data field from the current table cell and adds the value to the specified dictionary. (Overrides DataControlField.ExtractValuesFromCell(IOrderedDictionary, DataControlFieldCell, DataControlRowState, Boolean).)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetAttribute Retrieves the specified attribute value.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Initialize Performs basic instance initialization for a data control field. (Inherited from DataControlField.)
Public method InitializeCell Adds text or controls to the specified cell. (Overrides DataControlField.InitializeCell(DataControlFieldCell, DataControlCellType, DataControlRowState, Int32).)
Protected method LoadViewState Restores the data source view's previously saved view state. (Inherited from DataControlField.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnFieldChanged Raises the FieldChanged event. (Inherited from DataControlField.)
Protected method SaveViewState Saves the changes made to the DataControlField view state since the time the page was posted back to the server. (Inherited from DataControlField.)
Public method SetAttribute Sets an attribute that is associated with the DynamicField object.
Public method ToString Returns a string that represents this DataControlField object. (Inherited from DataControlField.)
Protected method TrackViewState Causes the DataControlField object to track changes to its view state so they can be stored in the control's ViewState property and persisted across requests for the same page. (Inherited from DataControlField.)
Public method ValidateSupportsCallback When overridden in a derived class, signals that the controls contained by a field support callbacks. (Inherited from DataControlField.)
Top
  Name Description
Public Extension Method ConvertEditedValue Returns the value provided by a user for a control that is being validated. (Defined by DynamicDataExtensions.)
Public Extension Method FormatEditValue Formats the specified field value by using the specified formatting options. (Defined by DynamicDataExtensions.)
Public Extension Method FormatValue Formats the specified field value by using the specified formatting options. (Defined by DynamicDataExtensions.)
Top
  Name Description
Explicit interface implemetation Private property IDataSourceViewSchemaAccessor.DataSourceViewSchema Infrastructure. Gets or sets the schema associated with this DataControlField object. (Inherited from DataControlField.)
Explicit interface implemetation Private property IStateManager.IsTrackingViewState Infrastructure. Gets a value indicating whether the DataControlField object is saving changes to its view state. (Inherited from DataControlField.)
Explicit interface implemetation Private method IStateManager.LoadViewState Infrastructure. Restores the data control field's previously saved view state. (Inherited from DataControlField.)
Explicit interface implemetation Private method IStateManager.SaveViewState Infrastructure. Saves the changes made to the DataControlField view state since the time the page was posted back to the server. (Inherited from DataControlField.)
Explicit interface implemetation Private method IStateManager.TrackViewState Infrastructure. Causes the DataControlField object to track changes to its view state so they can be stored in the control's ViewState property and persisted across requests for the same page. (Inherited from DataControlField.)
Top

In this topic:

Introduction

The DynamicField class is used by data-bound controls, such as the GridView and DetailsView controls, 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.

Declarative Syntax

<asp:DynamicField 
    AccessibleHeaderText="string"     
    ApplyFormatInEditMode="true|false"  
    ControlStyle-BackColor="color name|#dddddd" 
    ControlStyle-BorderColor="color name|#dddddd" 
    ControlStyle-BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|
       Ridge|Inset|Outset"  
    ControlStyle-BorderWidth="size"  
    ControlStyle-CssClass="string" 
    ControlStyle-Font-Bold="true|false" 
    ControlStyle-Font-Italic="true|false" 
    ControlStyle-Font-Names="string" 
    ControlStyle-Font-Overline="true|false"  
    ControlStyle-Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
       Large|X-Large|XX-Large" 
    ControlStyle-Font-Strikeout="true|false"   
    ControlStyle-Font-Underline="true|false"   
    ControlStyle-ForeColor="color name|#dddddd"   
    ControlStyle-Height="size" 
    ControlStyle-Width="size" 
    ConvertEmptyStringToNull="true|false"  
    DataField="string" 
    DataFormatString="string"   
    FooterStyle-BackColor="color name|#dddddd" 
    FooterStyle-BorderColor="color name|#dddddd" 
    FooterStyle-BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|
       Ridge|Inset|Outset"  
    FooterStyle-BorderWidth="size"  
    FooterStyle-CssClass="string" 
    FooterStyle-Font-Bold="true|false" 
    FooterStyle-Font-Italic="true|false" 
    FooterStyle-Font-Names="string" 
    FooterStyle-Font-Overline="true|false"  
    FooterStyle-Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
       Large|X-Large|XX-Large" 
    FooterStyle-Font-Strikeout="true|false"   
    FooterStyle-Font-Underline="true|false"   
    FooterStyle-ForeColor="color name|#dddddd"   
    FooterStyle-Height="size" 
    FooterStyle-Width="size" 
    FooterStyle-HorizontalAlign="Center|Justify|Left|NotSet|Right" 
    FooterStyle-VerticalAlign="Bottom|Middle|NotSet|Top" 
    FooterStyle-Wrap="true|false"   
    HeaderImageUrl="uri"
    HeaderStyle-BackColor="color name|#dddddd" 
    HeaderStyle-BorderColor="color name|#dddddd" 
    HeaderStyle-BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|
       Ridge|Inset|Outset"  
    HeaderStyle-BorderWidth="size"  
    HeaderStyle-CssClass="string" 
    HeaderStyle-Font-Bold="true|false" 
    HeaderStyle-Font-Italic="true|false" 
    HeaderStyle-Font-Names="string" 
    HeaderStyle-Font-Overline="true|false"  
    HeaderStyle-Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
       Large|X-Large|XX-Large" 
    HeaderStyle-Font-Strikeout="true|false"   
    HeaderStyle-Font-Underline="true|false"   
    HeaderStyle-ForeColor="color name|#dddddd"   
    HeaderStyle-Height="size" 
    HeaderStyle-Width="size" 
    HeaderStyle-HorizontalAlign="Center|Justify|Left|NotSet|Right" 
    HeaderStyle-VerticalAlign="Bottom|Middle|NotSet|Top" 
    HeaderStyle-Wrap="true|false"   
    HeaderText="string"
    InsertVisible="true|false"    
    ItemStyle-BackColor="color name|#dddddd" 
    ItemStyle-BorderColor="color name|#dddddd" 
    ItemStyle-BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|
       Ridge|Inset|Outset"  
    ItemStyle-BorderWidth="size"  
    ItemStyle-CssClass="string" 
    ItemStyle-Font-Bold="true|false" 
    ItemStyle-Font-Italic="true|false" 
    ItemStyle-Font-Names="string" 
    ItemStyle-Font-Overline="true|false"  
    ItemStyle-Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
       Large|X-Large|XX-Large" 
    ItemStyle-Font-Strikeout="true|false"   
    ItemStyle-Font-Underline="true|false"   
    ItemStyle-ForeColor="color name|#dddddd"   
    ItemStyle-Height="size" 
    ItemStyle-Width="size" 
    ItemStyle-HorizontalAlign="Center|Justify|Left|NotSet|Right" 
    ItemStyle-VerticalAlign="Bottom|Middle|NotSet|Top" 
    ItemStyle-Wrap="true|false"   
    NullDisplayText="string" 
    ReadOnly="true|false"  
    ShowHeader="true|false"  
    SortExpression="string" 
    UIHint="string" 
    ValidationGroup="string" 
    Visible="true|false" 
    />
<asp:DynamicField />

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  protected void Page_Init(object sender, EventArgs e)
  {
    DynamicDataManager1.RegisterControl(CustomersGridView);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>DynamicField Sample</title>
  <link href="~/Site.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <form id="form1" runat="server">
    <div>

      <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"
        AutoGenerateColumns="false"
        AutoGenerateEditButton="true"
        AutoGenerateDeleteButton="true"
        DataSourceID="CustomersDataSource"
        AllowPaging="true"
        AllowSorting="true"
        CssClass="gridview">
        <Columns>
          <asp:DynamicField DataField="CustomerID" />
          <asp:DynamicField DataField="FirstName" />
          <asp:DynamicField DataField="LastName" />
        </Columns>        
      </asp:GridView>

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

    </div>
  </form>
</body>
</html>


.NET Framework

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ