संपादित करें

इसके माध्यम से साझा किया गया


DynamicField Class

Definition

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

public ref class DynamicField : System::Web::UI::WebControls::DataControlField, System::Web::DynamicData::IFieldFormattingOptions, System::Web::UI::IAttributeAccessor
public class DynamicField : System.Web.UI.WebControls.DataControlField, System.Web.DynamicData.IFieldFormattingOptions, System.Web.UI.IAttributeAccessor
type DynamicField = class
    inherit DataControlField
    interface IAttributeAccessor
    interface IFieldFormattingOptions
Public Class DynamicField
Inherits DataControlField
Implements IAttributeAccessor, IFieldFormattingOptions
Inheritance
DynamicField
Implements

Examples

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>
<%@ 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">
  
  Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)    
    DynamicDataManager1.RegisterControl(CustomersGridView)
  End Sub
  
</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>

Remarks

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 />

Constructors

DynamicField()

Initializes a new instance of the DynamicField class.

Properties

AccessibleHeaderText

Gets or sets text that is rendered as the AbbreviatedText property value in some controls.

(Inherited from DataControlField)
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.

Column

Gets the MetaColumn object that this DynamicField object is associated with.

Control

Gets a reference to the data control that the DataControlField object is associated with.

(Inherited from DataControlField)
ControlStyle

Gets the style of any Web server controls contained by the DataControlField object.

(Inherited from DataControlField)
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.

DataField

Gets or sets the name of the data field to bind the DynamicField object to.

DataFormatString

Gets or sets the string that specifies the display format for the value of the data field.

DesignMode

Gets a value indicating whether a data control field is currently viewed in a design-time environment.

(Inherited from DataControlField)
FooterStyle

Gets or sets the style of the footer of the data control field.

(Inherited from DataControlField)
FooterText

Gets or sets the text that is displayed in the footer item of a data control field.

(Inherited from DataControlField)
HeaderImageUrl

Gets or sets the URL of an image that is displayed in the header item of a data control field.

(Inherited from DataControlField)
HeaderStyle

Gets or sets the style of the header of the data control field.

(Inherited from DataControlField)
HeaderText

Gets or sets the text that is displayed in the header of the data-bound control that contains the DynamicField object.

HtmlEncode

Gets or sets a value that indicates whether data field values are HTML-encoded before they are displayed in a DynamicField object.

InsertVisible

Gets a value indicating whether the DataControlField object is visible when its parent data-bound control is in insert mode.

(Inherited from DataControlField)
IsTrackingViewState

Gets a value indicating whether the DataControlField object is saving changes to its view state.

(Inherited from DataControlField)
ItemStyle

Gets the style of any text-based content displayed by a data control field.

(Inherited from DataControlField)
NullDisplayText

Gets or sets the caption that is displayed for a data field when the field value is null.

ReadOnly

Gets the read-only state of the dynamic field.

ShowHeader

Gets or sets a value indicating whether the header item of a data control field is rendered.

(Inherited from DataControlField)
SortExpression

Gets or sets the sort expression that is used when the data field is used to sort the data source by.

UIHint

Gets or sets the field template to use for displaying the data field.

ValidateRequestMode

Gets or sets a value that specifies whether the control validates client input.

ValidateRequestMode

Gets or sets a value that specifies whether the control validates client input.

(Inherited from DataControlField)
ValidationGroup

Gets the ValidationGroup object that this DynamicField object is associated with.

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)
Visible

Gets or sets a value indicating whether a data control field is rendered.

(Inherited from DataControlField)

Methods

CloneField()

Creates a duplicate copy of the current DataControlField-derived object.

(Inherited from DataControlField)
ConfigureDynamicControl(DynamicControl)

Provides a mechanism to modify a DynamicControl object that was created by the InitializeCell(DataControlFieldCell, DataControlCellType, DataControlRowState, Int32) method.

CopyProperties(DataControlField)

Copies the properties of the current DynamicField object to the specified DataControlField object.

CreateDynamicControl()

Provides a mechanism for classes that derive from DynamicField to override how a DynamicControl object is created.

CreateField()

Creates and returns a new instance of the DynamicField class.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
ExtractValuesFromCell(IOrderedDictionary, DataControlFieldCell, DataControlRowState, Boolean)

Extracts the value of the data field from the current table cell and adds the value to the specified dictionary.

GetAttribute(String)

Retrieves the specified attribute value.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
Initialize(Boolean, Control)

Performs basic instance initialization for a data control field.

(Inherited from DataControlField)
InitializeCell(DataControlFieldCell, DataControlCellType, DataControlRowState, Int32)

Adds text or controls to the specified cell.

LoadViewState(Object)

Restores the data source view's previously saved view state.

(Inherited from DataControlField)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnFieldChanged()

Raises the FieldChanged event.

(Inherited from DataControlField)
SaveViewState()

Saves the changes made to the DataControlField view state since the time the page was posted back to the server.

(Inherited from DataControlField)
SetAttribute(String, String)

Sets an attribute that is associated with the DynamicField object.

ToString()

Returns a string that represents this DataControlField object.

(Inherited from DataControlField)
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)
ValidateSupportsCallback()

When overridden in a derived class, signals that the controls contained by a field support callbacks.

(Inherited from DataControlField)

Explicit Interface Implementations

IDataSourceViewSchemaAccessor.DataSourceViewSchema

Gets or sets the schema associated with this DataControlField object.

(Inherited from DataControlField)
IStateManager.IsTrackingViewState

Gets a value indicating whether the DataControlField object is saving changes to its view state.

(Inherited from DataControlField)
IStateManager.LoadViewState(Object)

Restores the data control field's previously saved view state.

(Inherited from DataControlField)
IStateManager.SaveViewState()

Saves the changes made to the DataControlField view state since the time the page was posted back to the server.

(Inherited from DataControlField)
IStateManager.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)

Extension Methods

ConvertEditedValue(IFieldFormattingOptions, String)

Returns the value provided by a user for a control that is being validated.

FormatEditValue(IFieldFormattingOptions, Object)

Formats the specified field value by using the specified formatting options.

FormatValue(IFieldFormattingOptions, Object)

Formats the specified field value by using the specified formatting options.

Applies to

See also