System.Web.UI.WebControls.GridView.Columns Property

Gets a collection of System.Web.UI.WebControls.DataControlField objects that represent the column fields in a System.Web.UI.WebControls.GridView control.

Syntax

[System.ComponentModel.DefaultValue(null)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.ComponentModel.MergableProperty(false)]
[System.ComponentModel.Editor("System.Web.UI.Design.WebControls.DataControlFieldTypeEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual DataControlFieldCollection Columns { get; }

Value

Documentation for this section has not yet been entered.

Remarks

A column field represents a column in a System.Web.UI.WebControls.GridView control. The GridView.Columns property (collection) is used to store all the explicitly declared column fields that get rendered in the System.Web.UI.WebControls.GridView control. You can also use the GridView.Columns collection to programmatically manage the collection of column fields.

Note:

Explicitly declared column fields can be used in combination with automatically generated column fields. When both are used, explicitly declared column fields are rendered first, followed by the automatically generated column fields. Automatically generated column fields are not added to the GridView.Columns collection.

The column fields are displayed in the System.Web.UI.WebControls.GridView control in the order that the column fields appear in the GridView.Columns collection. The following table shows the different column field classes that derive from the System.Web.UI.WebControls.DataControlField class and can be used in the GridView.Columns collection.

System.Web.UI.WebControls.BoundField

Displays the value of a field in a data source. This is the default column type of the System.Web.UI.WebControls.GridView control.

System.Web.UI.WebControls.ButtonField

Displays a command button for each item in the System.Web.UI.WebControls.GridView control. This enables you to create a column of custom button controls, such as the Add or the Remove button.

System.Web.UI.WebControls.CheckBoxField

Displays a check box for each item in the System.Web.UI.WebControls.GridView control. This column field type is commonly used to display fields with a Boolean value.

System.Web.UI.WebControls.CommandField

Displays predefined command buttons to perform select, edit, or delete operations.

System.Web.UI.WebControls.HyperLinkField

Displays the value of a field in a data source as a hyperlink. This column field type enables you to bind a second field to the hyperlink's URL.

System.Web.UI.WebControls.ImageField

Displays an image for each item in the System.Web.UI.WebControls.GridView control.

System.Web.UI.WebControls.TemplateField

Displays user-defined content for each item in the System.Web.UI.WebControls.GridView control, according to a specified template. This column field type enables you to create a custom column field.

Although you can programmatically add column fields to the GridView.Columns collection, it is easier to list the column fields declaratively in the System.Web.UI.WebControls.GridView control and then use the DataControlField.Visible property of each column field to show or hide each column field.

If the DataControlField.Visible property of a column field is set to false, the column is not displayed in the System.Web.UI.WebControls.GridView control and the data for the column does not make a round trip to the client. If you want the data for a column that is not visible to make a round trip, add the field name to the GridView.DataKeyNames property.

Requirements

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