AutoGeneratedField Class
Assembly: System.Web (in system.web.dll)
The AutoGeneratedField class is used to represent an automatically generated field in a data-bound control, such as GridView or DetailsView. 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).
Note: |
|---|
| 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). |
The AutoGeneratedField class is intended for use internally by data-bound controls. 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. Although you can programmatically add an AutoGeneratedField object to a field collection, this design pattern should be avoided.
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.
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; } } }
System.Web.UI.WebControls.DataControlField
System.Web.UI.WebControls.BoundField
System.Web.UI.WebControls.AutoGeneratedField
Note: