DataGridColumnCollection.Add Method

Appends the specified DataGridColumn-derived column object to the end of the DataGridColumnCollection collection.

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

public:
void Add (
	DataGridColumn^ column
)
public void Add (
	DataGridColumn column
)
public function Add (
	column : DataGridColumn
)
Not applicable.

Parameters

column

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.

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

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

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show: