Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DataGrid.Columns Property

Gets a collection of objects that represent the columns of the DataGrid control.

[Visual Basic]
Public Overridable ReadOnly Property Columns As _
   DataGridColumnCollection
[C#]
public virtual DataGridColumnCollection Columns {get;}
[C++]
public: __property virtual DataGridColumnCollection* get_Columns();
[JScript]
public function get Columns() : DataGridColumnCollection;

Property Value

A DataGridColumnCollection object that contains a collection of objects that represent the columns of the DataGrid control.

Remarks

Use this property to programmatically control the collection of columns in the DataGrid control. The Columns collection contains explicitly declared columns that get rendered in the DataGrid 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 DataGrid 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 DataGridColumn class and can be used in the Columns collection.

Column Type Description
BoundColumn Displays a column bound to a field in a data source. It displays each item in the field as text. This is the default column type of the DataGrid control.
ButtonColumn Displays a command button for each item in the column. This allows you to create a column of custom button controls, such as the Add or Remove button.
EditCommandColumn Displays a column that contains editing commands for each item in the column.
HyperLinkColumn Displays the contents of each item in the column as a hyperlink. The contents of the column can be bound to a field in a data source or static text.
TemplateColumn Displays each item in the column following a specified template. This allows you to provide custom controls in the column.
Note   Although you can programmatically add columns to the Columns collection, it is easier to list the columns statically and then use the Visible property to show or hide the column.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

DataGrid Class | DataGrid Members | System.Web.UI.WebControls Namespace | DataGridColumn | BoundColumn | ButtonColumn | EditCommandColumn | HyperLinkColumn | TemplateColumn

Show:
© 2015 Microsoft