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

Posted by Nir on Stack Overflow See other posts from Stack Overflow or by Nir
Published on 2010-03-31T11:41:59Z Indexed on 2010/03/31 12:03 UTC
Read the original article Hit count: 219

Filed under:
|
|

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 GridView like this:

gridView.DataSource = dt;
gridView.DataBind();

But I'd like the GridView to display "b" first (leftmost).

Important point: I'm using this to export to Excel and there's no actual output to screen, using:

 HtmlTextWriter htw = new HtmlTextWriter(sw);
 gridView.RenderControl(htw);

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET