System.Web.UI.WebControls.DataControlFieldCollection Class

Represents a collection of System.Web.UI.WebControls.DataControlField objects that are used by data-bound controls such as System.Web.UI.WebControls.GridView and System.Web.UI.WebControls.DetailsView.

See Also: DataControlFieldCollection Members

Syntax

public sealed class DataControlFieldCollection : System.Web.UI.StateManagedCollection

Remarks

The System.Web.UI.WebControls.DataControlFieldCollection class represents a collection of System.Web.UI.WebControls.DataControlField objects used by data-bound controls to specify how their child controls are presented. The System.Web.UI.WebControls.DataControlFieldCollection class derives from System.Web.UI.StateManagedCollection, an abstract base collection class used specifically to store System.Web.UI.IStateManager objects.

A System.Web.UI.StateManagedCollection object influences the behavior of a System.Web.UI.WebControls.DataControlFieldCollection object. System.Web.UI.WebControls.DataControlField objects that are dynamically added to the collection will be re-added to the control when state is restored. This means that a field needs to be added, removed, or changed just once instead of on each postback, as most collection types in ASP.NET require.

(The System.Web.UI.WebControls.DataControlField class implements the System.Web.UI.IStateManager interface, which enables it to store its state in ASP.NET view state. )

Use the System.Web.UI.WebControls.DataControlFieldCollection class to programmatically manage a set of System.Web.UI.WebControls.DataControlField objects. Note that it is more common to define these fields declaratively.

You can add, insert, and remove System.Web.UI.WebControls.DataControlField objects using the appropriate methods of the System.Web.UI.WebControls.DataControlFieldCollection class. To programmatically retrieve System.Web.UI.WebControls.DataControlField objects from a collection, use one of following methods:

The System.Web.UI.StateManagedCollection.Count property specifies the total number of items in the collection, and is commonly used to determine the upper bound of the collection. You can add items to and remove items from the collection using the DataControlFieldCollection.Add(DataControlField), DataControlFieldCollection.Insert(int, DataControlField), DataControlFieldCollection.Remove(DataControlField), and DataControlFieldCollection.RemoveAt(int) methods.

If you are using the System.Web.UI.WebControls.GridView or System.Web.UI.WebControls.DetailsView control, the System.Web.UI.WebControls.DataControlField objects that are automatically created (for example, when the GridView.AutoGenerateColumns property is true) are not stored in the publicly accessible fields collection. You can only access and manipulate System.Web.UI.WebControls.DataControlField objects that are not automatically generated.

The following table lists the different data control field classes and how they are used.

System.Web.UI.WebControls.DataControlField

The abstract base class for all fields.

System.Web.UI.WebControls.BoundField

A data-bound control field that is used to bind to text or data retrieved from an ASP.NET data source control.

System.Web.UI.WebControls.ButtonFieldBase

A data-bound control field that encapsulates general button functionality. System.Web.UI.WebControls.ButtonField and System.Web.UI.WebControls.CheckBoxField are derived from it.

System.Web.UI.WebControls.ButtonField

A data-bound control field that displays at least one button.

System.Web.UI.WebControls.CheckBoxField

A data-bound control field that displays a System.Web.UI.WebControls.CheckBox control.

System.Web.UI.WebControls.CommandField

A data-bound control field that displays actions that can be performed on the data displayed by the row (or column), such as edit, update, or delete.

System.Web.UI.WebControls.HyperLinkField

A data-bound control field that displays a System.Web.UI.WebControls.HyperLink control.

System.Web.UI.WebControls.ImageField

A data-bound control field that displays an System.Web.UI.WebControls.Image control.

System.Web.UI.WebControls.TemplateField

A data-bound control field that displays custom content in a data-bound control.

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0