Following are the step to change order of your grid view column by code..
1st : make DataControlFieldCollection clone to your gridview columns
DataControlFieldCollection gvdcfCollection = grid.Columns.CloneFields();
2nd : clear the grid columns
grid.Columns.Clear();
3rd : Itreate through the clone copy and based on logic add or insert DataControlField into grid columns collection
grid.Columns.Add(gvdcfCollection[0]);
or
grid.Columns.Insert(0,gvdcfCollection[0]);
Note: If you have template column in your grid view then you have to make EnableViewState property of grid view to false.
Comments
Post a Comment