- 2 minutes to read
An individual column can be accessed using the GridViewColumnCollection.Item property by specifying one of the following column characteristics.
- Index - A column's index within the collection: the CollectionItem.Index property value.
- Name - A column's unique identifier name: the WebColumnBase.Name property value.
- FieldName - The name of a column's bound data source field: the GridViewDataColumn.FieldName property value.
- Caption - A column's caption: the WebColumnBase.Caption property value.
There is the following priority in using string column identifiers when searching for a column.
- First, the Name property match is searched for.
- Then, the first FieldName property match is searched for.
- At last, the first Caption property match is searched for.
Below is an example of accessing columns using different column characteristics.
// Accessing a column by specifying its unique identifier name - a column's Name property is set to 'MyColumn1'. GridViewColumn colMyColumn = BootstrpaGridView1.Columns["MyColumn1"]; // Accessing a column by specifying the name of the data source field to which it is bound - a column's FieldName property is set to 'Department'. GridViewColumn colDepartment = BootstrpaGridView1.Columns["Department"]; // Accessing a column by specifying its caption - a column's Caption property is set to 'Primary Phone'. GridViewColumn colPhone = BootstrpaGridView1.Columns["Primary Phone"]; // Accessing a column by its index within the Columns collection. GridViewColumn colFirstColumn = BootstrpaGridView1.Columns;