Accessing Columns
- 2 minutes to read
The ASPxGridView control stores its columns within the ASPxGridView.Columns collection. Use the ASPxGridView.VisibleColumns property to access the collection of visible columns.
The ASPxGridView allows you to access a column by its Index, Name, Caption, or FieldName property value. To do this, pass the column’s index, name, caption, or name of the bound data source field to a Item property overload.
The Item[String] property searches for a column in the following order:
- A column with the specified name
- A column with the specified data source field
- A column with the specified caption
Below is an example of how to use different column characteristics to access columns.
// Accesses the column whose Name property is set to 'MyColumn1'.
GridViewColumn colMyColumn = ASPxGridView1.Columns["MyColumn1"];
// Accesses the column whose FieldName property is set to 'Department'.
GridViewColumn colDepartment = ASPxGridView1.Columns["Department"];
// Accesses the column whose Caption property is set to 'Primary Phone'.
GridViewColumn colPhone = ASPxGridView1.Columns["Primary Phone"];
// Accesses the column whose Index property is set to '0'.
GridViewColumn colFirstColumn = ASPxGridView1.Columns[0];
You can also access client columns. To do this, use the ASPxClientGridView.GetColumn, ASPxClientGridView.GetColumnByField or ASPxClientGridView.GetColumnById method.