This documentation is archived and is not being maintained.

DataGridColumnCollection::RemoveAt Method

Removes a DataGridColumn-derived column object from the DataGridColumnCollection collection at the specified index.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public:
void RemoveAt(
	int index
)

Parameters

index
Type: System::Int32

The index of the DataGridColumn-derived column in the DataGridColumnCollection to remove.

ExceptionCondition
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.

NoteNote:

Although 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 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.

No code example is currently available or this language may not be supported.

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.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: