AutoGeneratedFieldProperties 类

定义

表示 AutoGeneratedField 对象的属性。Represents the properties of an AutoGeneratedField object. 此类不能被继承。This class cannot be inherited.

public ref class AutoGeneratedFieldProperties sealed : System::Web::UI::IStateManager
public sealed class AutoGeneratedFieldProperties : System.Web.UI.IStateManager
type AutoGeneratedFieldProperties = class
    interface IStateManager
Public NotInheritable Class AutoGeneratedFieldProperties
Implements IStateManager
继承
AutoGeneratedFieldProperties
实现

示例

下面的代码示例演示如何使用AutoGeneratedFieldProperties类在从DetailsView控件派生的AutoGeneratedField自定义控件中创建对象。The following code example demonstrates how to use the AutoGeneratedFieldProperties class to create an AutoGeneratedField object in 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

注解

数据绑定控件使用AutoGeneratedField 类在创建自动生成的字段时指定对象的属性。AutoGeneratedFieldPropertiesThe AutoGeneratedFieldProperties class is used by data-bound controls to specify the properties of an AutoGeneratedField object when creating an automatically generated field. 例如, 当DetailsView控件创建自动生成的行时, 它将创建一个AutoGeneratedFieldProperties具有行属性的对象CreateAutoGeneratedRow并将其传递给方法。For example, when the DetailsView control creates an automatically generated row, it creates an AutoGeneratedFieldProperties object with the row's properties and passes it to the CreateAutoGeneratedRow method. 同样, 在GridView创建自动生成AutoGeneratedFieldProperties的列时CreateAutoGeneratedColumn , 控件将对象传递给方法。Likewise, the GridView control passes an AutoGeneratedFieldProperties object to the CreateAutoGeneratedColumn method when creating an automatically generated column.

备注

此类通常仅在扩展GridViewDetailsView控件时使用。This class is typically used only when extending the GridView or DetailsView control.

可以通过AutoGeneratedField DataField设置属性来指定要绑定到对象的字段名称。You can specify the name of the field to bind to an AutoGeneratedField object by setting the DataField property. 若要指定字段值的数据类型, 请设置Type属性。To specify the data type of the field values, set the Type property. 您可以通过将IsReadOnly属性设置为来true阻止用户修改字段值。You can prevent users from modifying the field values by setting the IsReadOnly property to true. 还可以通过AutoGeneratedField Name设置属性来向对象分配名称。You can also assign a name to an AutoGeneratedField object by setting the Name property.

构造函数

AutoGeneratedFieldProperties()

初始化 AutoGeneratedFieldProperties 类的新实例。Initializes a new instance of the AutoGeneratedFieldProperties class.

属性

DataField

获取或设置绑定到 AutoGeneratedField 对象的字段的名称。Gets or sets the name of the field bound to the AutoGeneratedField object.

IsReadOnly

获取或设置一个值,该值指示是否可以以编辑模式修改 AutoGeneratedField 对象中显示的值。Gets or sets a value indicating whether the values displayed in an AutoGeneratedField object can be modified in edit mode.

Name

获取或设置 AutoGeneratedField 对象的名称。Gets or sets the name of the AutoGeneratedField object.

Type

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

方法

Equals(Object)

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

(继承自 Object)
GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

IStateManager.IsTrackingViewState

获取一个值,该值指示 AutoGeneratedFieldProperties 对象是否跟踪其视图状态更改。Gets a value indicating whether the AutoGeneratedFieldProperties object is tracking its view-state changes.

IStateManager.LoadViewState(Object)

加载以前保存的 AutoGeneratedFieldProperties 对象的视图状态。Loads the previously saved view state of the AutoGeneratedFieldProperties object.

IStateManager.SaveViewState()

保存 AutoGeneratedFieldProperties 对象的当前视图状态。Saves the current view state of the AutoGeneratedFieldProperties object.

IStateManager.TrackViewState()

标记开始跟踪并将视图状态更改保存到 AutoGeneratedFieldProperties 对象的起点。Marks the starting point at which to begin tracking and saving view-state changes to the AutoGeneratedFieldProperties object.

适用于

另请参阅