System.Web.UI.WebControls Namespace DataGridColumnCollection Class
Removes the specified DataGridColumn from the collection.
[ VB ]
Public Sub Remove ( _
ByVal column As DataGridColumn _
)
[ C# ]
public void Remove (
DataGridColumn column
);
[ C++ ]
public: void Remove (
DataGridColumn* column
);
[ JScript ]
public function Remove (
column : DataGridColumn
);
- column
- The DataGridColumn to remove from the collection.
Use this method to remove the specified DataGridColumn derived object from a DataGridColumnCollection.
The DataGrid control does not store the contents of its Columns collection into the view state. To add or remove a column dynamically, you must programmaticallt 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.
NOTE: While you can programmatically add columns to or remove columns from the Columns collection of the DataGrid control, it is easier to list the columns statically and then use the Visible property to display or hide each column.
The following example demonstrates how to use the Remove method to dynamically remove a column from a DataGrid control.
void Page_Init ( Object src, EventArgs e ) {
myGrid.Columns.Remove ( myGrid.Columns [ 0 ] );
}
Sub Page_Init ( src As Object, e As EventArgs )
myGrid.Columns.Remove ( myGrid.Columns ( 0 ) )
End Sub |
|
C# |
VB |
DataGridColumnCollection Members RemoveAt Add AddAt