System.Web.UI.WebControls Namespace DataControlFieldCollection Class
.NET Framework version 2.0
Removes a DataControlField 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
);
- index
- The zero-based index of the DataControlField in the collection to remove.
Use this method to remove a DataControlField derived object from a DataControlFieldCollection at the specified index.
The GridView 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 GridView control can reload its state and rebuild itself. Otherwise, the changes to the Columns collection are not reflected in the GridView control when it is displayed.
NOTE: While you can programmatically add columns to or remove columns from the Columns collection of the GridView 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 RemoveAt method to dynamically remove a column from a GridView control.
void Page_Init ( Object src, EventArgs e ) {
myGrid.Columns.RemoveAt ( 0 );
}
Sub Page_Init ( src As Object, e As EventArgs )
myGrid.Columns.RemoveAt ( 0 )
End Sub |
|
C# |
VB |
DataControlFieldCollection Members Remove Add