DataGridColumnCollection::Add Method (DataGridColumn^)
Appends the specified DataGridColumn-derived column object to the end of the DataGridColumnCollection collection.
Assembly: System.Web (in System.Web.dll)
Parameters
- column
-
Type:
System.Web.UI.WebControls::DataGridColumn^
The DataGridColumn-derived column object to append to the DataGridColumnCollection.
Use this method to add a DataGridColumn-derived column object to the end of a 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 Add 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 class.
Available since 1.1
