views:

221

answers:

1

How can I change gridview templatecolumn order dynamically?

A: 
  1. Iterate through all coloumns of the GridView object and Store them in a collection.

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

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

     gv.Columns.Clear();
     foreach (DataControlField coloumn in coloumns)
     {
         gv.Columns.Add(coloumn);
     }
    
this. __curious_geek
http://geekswithblogs.net/dotNETvinz/archive/2009/06/03/move--autogenerate-columns-at-leftmost-part-of-the-gridview.aspx
hotcoder