C#: Changing the order of columns when binding DataTable to a GridView

后端 未结 2 687
鱼传尺愫
鱼传尺愫 2021-01-06 08:16

How is it possible to change the displayed order of columns from a DataTable?

For example, dataTable \"dt\" contains two columns \"a\" and \"b\". I bind it to a Gr

2条回答
  •  醉梦人生
    2021-01-06 08:51

    yes you can do it in the front end. Something along these lines:

    
        
            
            
        
    
    

    EDIT:

    No front end you say? That's cool - I like a challenge:

                gridView.AutoGenerateColumns = false;
            gridView.Columns.Add(new BoundField { DataField = "b" });
            gridView.Columns.Add(new BoundField { DataField = "a" });
    

    (It's cool to assume C#3 these days isn't it?)

提交回复
热议问题