The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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)

public sealed class AutoGeneratedField : BoundField
public final class AutoGeneratedField extends BoundField
public final class AutoGeneratedField extends BoundField
Not applicable.

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 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft