AutoGeneratedField 类

定义

表示数据绑定控件中自动生成的字段。Represents an automatically generated field in a data-bound control. 此类不能被继承。This class cannot be inherited.

public ref class AutoGeneratedField sealed : System::Web::UI::WebControls::BoundField
public sealed class AutoGeneratedField : System.Web.UI.WebControls.BoundField
type AutoGeneratedField = class
    inherit BoundField
Public NotInheritable Class AutoGeneratedField
Inherits BoundField
继承
AutoGeneratedField

示例

下面的示例演示如何为派生AutoGeneratedField DetailsView自控件的自定义控件创建对象。The following example demonstrates how to create an AutoGeneratedField object for a custom control that derives from the DetailsView control.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;
using System.Web;

namespace Samples.AspNet.CS.Controls
{
      
    [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public class SimpleCustomControl : DetailsView
    {

        protected override AutoGeneratedField CreateAutoGeneratedRow(AutoGeneratedFieldProperties fieldProperties) 
        {

            // Create an AutoGeneratedField object.
            AutoGeneratedField field = new AutoGeneratedField(fieldProperties.DataField);

            // Set the properties of the AutoGeneratedField using
            // the values from the AutoGeneratedFieldProperties 
            // object contained in the fieldProperties parameter.
            ((IStateManager)field).TrackViewState();
            field.HeaderText = fieldProperties.Name;
            field.SortExpression = fieldProperties.Name;
            field.ReadOnly = fieldProperties.IsReadOnly;
            field.DataType = fieldProperties.Type;

            return field;
        }
        
    }
}


Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions
Imports System.Web

Namespace Samples.AspNet.VB.Controls

    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> Public Class SimpleCustomControl
        Inherits System.Web.UI.WebControls.DetailsView

        Protected Overrides Function CreateAutoGeneratedRow(ByVal fieldProperties As AutoGeneratedFieldProperties) As AutoGeneratedField

            ' Create an AutoGeneratedField object.
            Dim field As New AutoGeneratedField(fieldProperties.DataField)

            ' Set the properties of the AutoGeneratedField using
            ' the values from the AutoGeneratedFieldProperties 
            ' object contained in the fieldProperties parameter.
            CType(field, IStateManager).TrackViewState()
            field.HeaderText = fieldProperties.Name
            field.SortExpression = fieldProperties.Name
            field.ReadOnly = fieldProperties.IsReadOnly
            field.DataType = fieldProperties.Type

            Return field

        End Function

    End Class

End Namespace

注解

类用于表示数据绑定控件中自动生成的字段, GridView例如或DetailsViewAutoGeneratedFieldThe AutoGeneratedField class is used to represent an automatically generated field in a data-bound control, such as GridView or DetailsView. 当适当true的属性设置为 (例如AutoGenerateColumns , 该控件的属性GridViewDetailsView控件的AutoGenerateRows属性) 时, 由数据绑定控件创建自动生成的字段。以此类推)。Automatically generated fields are created by a data-bound control when the appropriate property is set to true (for example, the AutoGenerateColumns property for the GridView control, the AutoGenerateRows property for the DetailsView control, and so on).

备注

自动生成的字段不会添加到数据绑定控件的字段Columns集合 (例如, GridView控件的集合DetailsViewFields控件的集合等)。Automatically generated fields are not added to the field collection of a data-bound control (for example, the Columns collection for the GridView control, the Fields collection for the DetailsView control, and so on).

AutoGeneratedField类供数据绑定控件在内部使用。The AutoGeneratedField class is intended for use internally by data-bound controls. 与其他数据字段BoundField(例如TemplateFieldCheckBoxField、等) 不同, AutoGeneratedField不能以声明方式将类放置在页上作为字段集合的一部分。Unlike other data fields (such as BoundField, CheckBoxField, TemplateField, and so on), the AutoGeneratedField class cannot be placed declaratively on a page as part of a field collection. 尽管可以通过编程方式将AutoGeneratedField对象添加到字段集合中, 但应避免使用此设计模式。Although you can programmatically add an AutoGeneratedField object to a field collection, this design pattern should be avoided.

由于自动生成的字段表示自动呈现字段, 因此数据绑定控件通常不允许用户修改AutoGeneratedField对象的属性。Because automatically generated fields represent the automatic rendering of a field, data-bound controls do not typically allow users to modify the properties of the AutoGeneratedField objects. 如果自动呈现功能不适合您的需要, 则为控件的字段集合定义您自己的数据字段。If the automatic rendering is not suitable for your needs, define your own data fields for the field collection of the control.

构造函数

AutoGeneratedField(String)

用指定的数据字段初始化 AutoGeneratedField 类的新实例。Initializes a new instance of the AutoGeneratedField class with the specified data field.

属性

AccessibleHeaderText

获取或设置某些控件中呈现为 AbbreviatedText 属性值的文本。Gets or sets text that is rendered as the AbbreviatedText property value in some controls.

(继承自 DataControlField)
ApplyFormatInEditMode

获取或设置一个值,该值指示包含 DataFormatString 对象的数据绑定控件处于编辑模式时,BoundField 属性指定的格式化字符串是否应用到字段值。Gets or sets a value indicating whether the formatting string specified by the DataFormatString property is applied to field values when the data-bound control that contains the BoundField object is in edit mode.

(继承自 BoundField)
Control

获取对数据控件的引用,该控件与 DataControlField 对象关联。Gets a reference to the data control that the DataControlField object is associated with.

(继承自 DataControlField)
ControlStyle

获取 DataControlField 对象所包含的任何 Web 服务器控件的样式。Gets the style of any Web server controls contained by the DataControlField object.

(继承自 DataControlField)
ConvertEmptyStringToNull

获取或设置一个值,该值指示在从数据源检索字段值时,是否将空字符串 ("") 值转换为 nullGets or sets a value indicating whether empty string ("") values are converted to null when the field values are retrieved from the data source.

DataField

获取或设置要绑定到 BoundField 对象的数据字段的名称。Gets or sets the name of the data field to bind to the BoundField object.

(继承自 BoundField)
DataFormatString

获取或设置一个字符串,该字符串指定 AutoGeneratedField 对象中每个图像的备用文本所呈现的格式。Gets or sets the string that specifies the format in which the alternate text for each image in an AutoGeneratedField object is rendered.

DataType

获取或设置在 AutoGeneratedField 对象中显示的值的数据类型。Gets or sets the data type of the values displayed in an AutoGeneratedField object.

DesignMode

获取一个值,该值指示数据控件字段当前是否在设计时环境中进行查看。Gets a value indicating whether a data control field is currently viewed in a design-time environment.

(继承自 DataControlField)
FooterStyle

获取或设置数据控件字段脚注的样式。Gets or sets the style of the footer of the data control field.

(继承自 DataControlField)
FooterText

获取或设置数据控件字段的脚注项中显示的文本。Gets or sets the text that is displayed in the footer item of a data control field.

(继承自 DataControlField)
HeaderImageUrl

获取或设置数据控件字段的标题项中显示的图像的 URL。Gets or sets the URL of an image that is displayed in the header item of a data control field.

(继承自 DataControlField)
HeaderStyle

获取或设置数据控件字段标头的样式。Gets or sets the style of the header of the data control field.

(继承自 DataControlField)
HeaderText

获取或设置显示在数据控件标头中的文本。Gets or sets the text that is displayed in the header of a data control.

(继承自 BoundField)
HtmlEncode

获取或设置一个值,该值指示在 BoundField 对象中显示字段值之前,是否对这些字段值进行 HTML 编码。Gets or sets a value indicating whether field values are HTML-encoded before they are displayed in a BoundField object.

(继承自 BoundField)
HtmlEncodeFormatString

获取或设置一个值,该值指示通过将 DataFormatString 属性应用于 BoundField 值而创建的文本在显示时是否应经过 HTML 编码。Gets or sets a value that indicates whether text that is created by applying the DataFormatString property to the BoundField value should be HTML encoded when it is displayed.

(继承自 BoundField)
InsertVisible

获取或设置一个值,该值指示 AutoGeneratedField 对象在插入模式中是否可见。Gets or sets a value indicating whether the AutoGeneratedField object is visible in insert mode.

IsTrackingViewState

获取一个值,该值指示 DataControlField 对象是否保存对其视图状态的更改。Gets a value indicating whether the DataControlField object is saving changes to its view state.

(继承自 DataControlField)
ItemStyle

获取由数据控件字段显示的任何基于文本的内容的样式。Gets the style of any text-based content displayed by a data control field.

(继承自 DataControlField)
NullDisplayText

获取或设置当字段值为 null 时为字段显示的标题。Gets or sets the caption displayed for a field when the field's value is null.

(继承自 BoundField)
ReadOnly

获取或设置一个值,该值指示是否可以在编辑模式中修改字段的值。Gets or sets a value indicating whether the value of the field can be modified in edit mode.

(继承自 BoundField)
ShowHeader

获取或设置一个值,该值指示是否呈现数据控件字段的标题项。Gets or sets a value indicating whether the header item of a data control field is rendered.

(继承自 DataControlField)
SortExpression

获取或设置数据源控件用来对数据进行排序的排序表达式。Gets or sets a sort expression that is used by a data source control to sort data.

(继承自 DataControlField)
SupportsHtmlEncode

获取一个值,该值指示 BoundField 对象是否支持 HTML 编码。Gets a value indicating whether HTML encoding is supported by a BoundField object.

(继承自 BoundField)
ValidateRequestMode

获取或设置确定控件是否验证客户端输入的值。Gets or sets a value that determines whether the control validates client input or not.

(继承自 BoundField)
ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原 DataControlField 对象的视图状态。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.

(继承自 DataControlField)
Visible

获取或设置指示是否呈现数据控件字段的值。Gets or sets a value indicating whether a data control field is rendered.

(继承自 DataControlField)

方法

CloneField()

创建当前 DataControlField 派生对象的副本。Creates a duplicate copy of the current DataControlField-derived object.

(继承自 DataControlField)
CopyProperties(DataControlField)

将当前 BoundField 对象的属性复制到指定的 DataControlField 对象。Copies the properties of the current BoundField object to the specified DataControlField object.

(继承自 BoundField)
CreateField()

创建一个空的 BoundField 对象。Creates an empty BoundField object.

(继承自 BoundField)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
ExtractValuesFromCell(IOrderedDictionary, DataControlFieldCell, DataControlRowState, Boolean)

使用指定的 IOrderedDictionary 对象中的值填充指定的 DataControlFieldCell 对象。Fills the specified IOrderedDictionary object with the values from the specified DataControlFieldCell object.

FormatDataValue(Object, Boolean)

设定 BoundField 对象内的单元格中的指定字段值。Formats the specified field value for a cell in the BoundField object.

(继承自 BoundField)
GetDesignTimeValue()

在设计器中呈现 BoundField 对象时,检索用作字段值的值。Retrieves the value used for a field's value when rendering the BoundField object in a designer.

(继承自 BoundField)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
GetValue(Control)

检索绑定到 BoundField 对象的字段值。Retrieves the value of the field bound to the BoundField object.

(继承自 BoundField)
Initialize(Boolean, Control)

初始化 BoundField 对象。Initializes the BoundField object.

(继承自 BoundField)
InitializeCell(DataControlFieldCell, DataControlCellType, DataControlRowState, Int32)

将指定的 TableCell 对象初始化为指定的行状态。Initializes the specified TableCell object to the specified row state.

(继承自 BoundField)
InitializeDataCell(DataControlFieldCell, DataControlRowState)

将指定的 TableCell 对象初始化为指定的行状态。Initializes the specified TableCell object to the specified row state.

(继承自 BoundField)
LoadViewState(Object)

还原以前为此字段存储的视图状态信息。Restores the previously stored view-state information for this field.

(继承自 BoundField)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnDataBindField(Object, EventArgs)

将字段值绑定到 BoundField 对象。Binds the value of a field to the BoundField object.

(继承自 BoundField)
OnFieldChanged()

引发 FieldChanged 事件。Raises the FieldChanged event.

(继承自 DataControlField)
SaveViewState()

保存在页回发到服务器后对 DataControlField 视图状态所做的更改。Saves the changes made to the DataControlField view state since the time the page was posted back to the server.

(继承自 DataControlField)
ToString()

返回表示此 DataControlField 对象的字符串。Returns a string that represents this DataControlField object.

(继承自 DataControlField)
TrackViewState()

使 DataControlField 对象跟踪对其视图状态所做的更改,以便这些更改可以存储在控件的 ViewState 属性中并且能够在同一页的不同请求间得以保持。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.

(继承自 DataControlField)
ValidateSupportsCallback()

确定 AutoGeneratedField 对象中所包含的控件是否支持回调。Determines whether the controls contained in an AutoGeneratedField object support callbacks.

显式界面实现

IDataSourceViewSchemaAccessor.DataSourceViewSchema

获取或设置与此 DataControlField 对象关联的架构。Gets or sets the schema associated with this DataControlField object.

(继承自 DataControlField)
IStateManager.IsTrackingViewState

获取一个值,该值指示 DataControlField 对象是否保存对其视图状态的更改。Gets a value indicating whether the DataControlField object is saving changes to its view state.

(继承自 DataControlField)
IStateManager.LoadViewState(Object)

将数据控件字段还原为保存过的前一视图状态。Restores the data control field's previously saved view state.

(继承自 DataControlField)
IStateManager.SaveViewState()

保存在页回发到服务器后对 DataControlField 视图状态所做的更改。Saves the changes made to the DataControlField view state since the time the page was posted back to the server.

(继承自 DataControlField)
IStateManager.TrackViewState()

使 DataControlField 对象跟踪对其视图状态所做的更改,以便这些更改可以存储在控件的 ViewState 属性中并且能够在同一页的不同请求间得以保持。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.

(继承自 DataControlField)

适用于

另请参阅