AutoGeneratedField(String) 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
用指定的数据字段初始化 AutoGeneratedField 类的新实例。
public:
AutoGeneratedField(System::String ^ dataField);
public AutoGeneratedField (string dataField);
new System.Web.UI.WebControls.AutoGeneratedField : string -> System.Web.UI.WebControls.AutoGeneratedField
Public Sub New (dataField As String)
参数
- dataField
- String
要绑定到 AutoGeneratedField 的数据字段的名称。
示例
以下示例演示如何在实现派DetailsView生自控件的AutoGeneratedField自定义控件时使用此构造函数创建类的新实例。
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 。 此构造函数通常由数据绑定控件使用, ((如 GridView 在创建自动生成的字段时)和 DetailsView) 。