Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change gridview templatecolumn order dynamically?

How can I change gridview templatecolumn order dynamically?

like image 501
hotcoder Avatar asked Jan 06 '10 07:01

hotcoder


1 Answers

  1. Iterate through all columns of the GridView object and Store them in a collection.

    List<DataControlField> columns = new List<DataControlField>();
    foreach (DataControlField column in gv.Columns)
    {
        columns.Add(column);
    }
    
  2. Rearrange the column-objects as you want in the collection.

    //Rearrange columns' collection..
    
  3. Clear all columns of the GridView object and add columns from the collection to GridView object.

     gv.Columns.Clear();
     foreach (DataControlField column in columns)
     {
         gv.Columns.Add(column);
     }
    
like image 152
this. __curious_geek Avatar answered Nov 13 '22 21:11

this. __curious_geek