DataGridColumnCollection::RemoveAt Method (Int32)
Removes a DataGridColumn-derived column object from the DataGridColumnCollection collection at the specified index.
Assembly: System.Web (in System.Web.dll)
Parameters
- index
-
Type:
System::Int32
The index of the DataGridColumn-derived column in the DataGridColumnCollection to remove.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | index is less than 0 or greater than Count. |
Use this method to remove a DataGridColumn-derived column object from a DataGridColumnCollection collection at the specified index.
The DataGrid control does not store the contents of its Columns collection in the view state. To add or remove a column dynamically, you must programmatically add or remove the column each time the page is refreshed. Provide a Page_Init function that adds or removes the column before the DataGrid control can reload its state and rebuild itself. Otherwise, the changes to the Columns collection are not reflected in the DataGrid control when it is displayed.
The following code example demonstrates how to use the RemoveAt method to remove a column from the DataGridColumnCollection collection. Note that the Columns property of the DataGrid control is the DataGridColumnCollection collection.
Available since 1.1
