asp.net.ph

DataGridColumnCollection.RemoveAt Method

System.Web.UI.WebControls Namespace   DataGridColumnCollection Class


Removes a DataGridColumn from the collection at the specified index.

[ VB ]
Public Sub RemoveAt ( _
   ByVal index As Integer _
)

[ C# ]
public void RemoveAt (
   int index
);

[ C++ ]
public: void RemoveAt (
   int index
);

[ JScript ]
public function RemoveAt (
   index : int
);

Parameters

index
The zero-based index of the DataGridColumn in the collection to remove.

Remarks

Use this method to remove a DataGridColumn derived object from a DataGridColumnCollection at the specified index.

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.

Example

The following example demonstrates how to use the RemoveAt method to dynamically remove a column from a DataGrid control.

void Page_Init ( Object src, EventArgs e ) {
   myGrid.Columns.RemoveAt ( 0 );
}
  C# VB

See Also

DataGridColumnCollection Members   Remove   Add   AddAt Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph