Export (0) Print
Expand All

DynamicField Class

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)

public class DynamicField : DataControlField, 
	IAttributeAccessor, IFieldFormattingOptions

The DynamicField type exposes the following members.

  NameDescription
Public methodDynamicFieldInitializes a new instance of the DynamicField class.
Top

  NameDescription
Public propertyAccessibleHeaderTextGets or sets text that is rendered as the AbbreviatedText property value in some controls. (Inherited from DataControlField.)
Public propertyApplyFormatInEditModeGets 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 propertyColumnGets the MetaColumn object that this DynamicField object is associated with.
Protected propertyControlGets a reference to the data control that the DataControlField object is associated with. (Inherited from DataControlField.)
Public propertyControlStyleGets the style of any Web server controls contained by the DataControlField object. (Inherited from DataControlField.)
Public propertyConvertEmptyStringToNullGets 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 propertyDataFieldGets or sets the name of the data field to bind the DynamicField object to.
Public propertyDataFormatStringGets or sets the string that specifies the display format for the value of the data field.
Protected propertyDesignModeGets a value indicating whether a data control field is currently viewed in a design-time environment. (Inherited from DataControlField.)
Public propertyFooterStyleGets or sets the style of the footer of the data control field. (Inherited from DataControlField.)
Public propertyFooterTextGets or sets the text that is displayed in the footer item of a data control field. (Inherited from DataControlField.)
Public propertyHeaderImageUrlGets or sets the URL of an image that is displayed in the header item of a data control field. (Inherited from DataControlField.)
Public propertyHeaderStyleGets or sets the style of the header of the data control field. (Inherited from DataControlField.)
Public propertyHeaderTextGets or sets the text that is displayed in the header of the data-bound control that contains the DynamicField object. (Overrides DataControlField.HeaderText.)
Public propertyHtmlEncodeGets or sets a value that indicates whether data field values are HTML-encoded before they are displayed in a DynamicField object.
Public propertyInsertVisibleGets a value indicating whether the DataControlField object is visible when its parent data-bound control is in insert mode. (Inherited from DataControlField.)
Protected propertyIsTrackingViewStateGets a value indicating whether the DataControlField object is saving changes to its view state. (Inherited from DataControlField.)
Public propertyItemStyleGets the style of any text-based content displayed by a data control field. (Inherited from DataControlField.)
Public propertyNullDisplayTextGets or sets the caption that is displayed for a data field when the field value is null.
Public propertyReadOnlyGets the read-only state of the dynamic field.
Public propertyShowHeaderGets or sets a value indicating whether the header item of a data control field is rendered. (Inherited from DataControlField.)
Public propertySortExpressionGets or sets the sort expression that is used when the data field is used to sort the data source by. (Overrides DataControlField.SortExpression.)
Public propertyUIHintGets or sets the field template to use for displaying the data field.
Public propertyValidateRequestModeGets or sets a value that specifies whether the control validates client input.
Public propertyValidationGroupGets the ValidationGroup object that this DynamicField object is associated with.
Protected propertyViewStateGets 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 propertyVisibleGets or sets a value indicating whether a data control field is rendered. (Inherited from DataControlField.)
Top

  NameDescription
Protected methodCloneFieldInfrastructure. Creates a duplicate copy of the current DataControlField-derived object. (Inherited from DataControlField.)
Protected methodConfigureDynamicControlProvides a mechanism to modify a DynamicControl object that was created by the InitializeCell method.
Protected methodCopyPropertiesCopies the properties of the current DynamicField object to the specified DataControlField object. (Overrides DataControlField.CopyProperties(DataControlField).)
Protected methodCreateDynamicControlProvides a mechanism for classes that derive from DynamicField to override how a DynamicControl object is created.
Protected methodCreateFieldCreates and returns a new instance of the DynamicField class. (Overrides DataControlField.CreateField().)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodExtractValuesFromCellExtracts 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 methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetAttributeRetrieves the specified attribute value.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializePerforms basic instance initialization for a data control field. (Inherited from DataControlField.)
Public methodInitializeCellAdds text or controls to the specified cell. (Overrides DataControlField.InitializeCell(DataControlFieldCell, DataControlCellType, DataControlRowState, Int32).)
Protected methodLoadViewStateRestores the data source view's previously saved view state. (Inherited from DataControlField.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnFieldChangedRaises the FieldChanged event. (Inherited from DataControlField.)
Protected methodSaveViewStateSaves the changes made to the DataControlField view state since the time the page was posted back to the server. (Inherited from DataControlField.)
Public methodSetAttributeSets an attribute that is associated with the DynamicField object.
Public methodToStringReturns a string that represents this DataControlField object. (Inherited from DataControlField.)
Protected methodTrackViewStateCauses 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 methodValidateSupportsCallbackWhen overridden in a derived class, signals that the controls contained by a field support callbacks. (Inherited from DataControlField.)
Top

  NameDescription
Public Extension MethodConvertEditedValueReturns the value provided by a user for a control that is being validated. (Defined by DynamicDataExtensions.)
Public Extension MethodFormatEditValueFormats the specified field value by using the specified formatting options. (Defined by DynamicDataExtensions.)
Public Extension MethodFormatValueFormats the specified field value by using the specified formatting options. (Defined by DynamicDataExtensions.)
Top

  NameDescription
Explicit interface implemetationPrivate propertyIDataSourceViewSchemaAccessor.DataSourceViewSchemaInfrastructure. Gets or sets the schema associated with this DataControlField object. (Inherited from DataControlField.)
Explicit interface implemetationPrivate propertyIStateManager.IsTrackingViewStateInfrastructure. Gets a value indicating whether the DataControlField object is saving changes to its view state. (Inherited from DataControlField.)
Explicit interface implemetationPrivate methodIStateManager.LoadViewStateInfrastructure. Restores the data control field's previously saved view state. (Inherited from DataControlField.)
Explicit interface implemetationPrivate methodIStateManager.SaveViewStateInfrastructure. 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 implemetationPrivate methodIStateManager.TrackViewStateInfrastructure. 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.5.3, 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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.
Show:
© 2014 Microsoft