Hi,
If we have set AutoGenerateColumns property of the GridView as true and binding it to a data source, we will not be able to remove columns from it using the Remove or RemoveAt functions of Columns.
myGridView.Columns.Remove or RemoveAt
So to remove the columns we can make use of RowDataBound event.
protected void myGridView _RowDataBound(object sender, GridViewRowEventArgs e){
// hide the second and third column
if (e.Row.RowType == DataControlRowType.DataRow){
e.Row.Cells[1].Visible=false;
e.Row.Cells[2].Visible=false;}
else
if (e.Row.RowType == DataControlRowType.Header){
e.Row.Cells[1].Visible = false;
e.Row.Cells[2].Visible = false;}
}
Hope it helps!!