System.Web.UI.WebControls Namespace GridView Class
.NET Framework version 2.0
Returns a collection of DataControlField objects that represent the columns in a GridView control.
Script |
[ DataControlFieldCollection variable = ] GridView.Columns |
This property can only be used programmatically; it cannot be set when declaring the control.
The property is read only with no default value.
Use this property to programmatically manage the collection of columns in the GridView control. The Columns collection contains explicitly declared columns that get rendered in the GridView control.
NOTE: Explicitly declared columns may be used in conjunction with automatically generated columns. When using both, explicitly declared columns will be rendered first, followed by the automatically generated columns. Automatically generated columns are not added to the Columns collection.
The order that the columns are displayed in the GridView control is controlled by the order that the columns appear in the Columns collection.
The following table shows the different column classes that derive from the DataControlField class and can be used in the Columns collection.
Column Type |
Description |
BoundField |
Displays a column bound to a field in a data source, that displays each row in the field as text. This is the default column type of the GridView control. |
ButtonField |
Displays a command button for each row in the column. This allows you to create a column of custom button controls, such as the Add or Remove button. |
CheckBoxField |
Displays a check box for each row in the GridView control. This column field type is commonly used to display fields with a Boolean value. |
CommandField |
Displays predefined command buttons to perform selecting, editing, or deleting operations. |
HyperLinkField |
Displays the contents of each row in the column as a hyperlink. The contents of the column can be bound to a field in a data source or static text. |
ImageField |
Displays an image for each row in the GridView control. |
TemplateField |
Displays each row in the column following a specified template. This allows you to provide custom controls in the column. |
NOTE: While you can programmatically add columns to the Columns collection, it is easier to list the columns declaratively and then use the Visible property to show or hide the column.
GridView Members DataControlField BoundField ButtonField CheckBoxField CommandField HyperLinkField ImageField TemplateField