This documentation is archived and is not being maintained.

AutoGeneratedField Class

Represents an automatically generated field in a data-bound control. This class cannot be inherited.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class AutoGeneratedField : BoundField

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


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.
            field.HeaderText = fieldProperties.Name;
            field.SortExpression = fieldProperties.Name;
            field.ReadOnly = fieldProperties.IsReadOnly;
            field.DataType = fieldProperties.Type;

            return field;


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0