DataGridColumnCollection::AddAt Method
Inserts a DataGridColumn-derived column object in the DataGridColumnCollection collection at the specified index.
Assembly: System.Web (in System.Web.dll)
Parameters
- index
- Type: System::Int32
The index location in the DataGridColumnCollection at which to insert the DataGridColumn-derived column.
- column
- Type: System.Web.UI.WebControls::DataGridColumn
The DataGridColumn-derived column to insert in the DataGridColumnCollection.
| Exception | Condition |
|---|---|
| ArgumentNullException | column is nullptr. |
Use this method to insert a DataGridColumn-derived column object at the specified index location in the DataGridColumnCollection collection.
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 AddAt method to dynamically add a column to the DataGrid control. Note that the Columns property of the DataGrid control is an instance of the DataGridColumnCollection collection.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: