Tim wrote:
> //DataGridColumn dgCol1;
> //DataGridColumn dgCol2;
> //int tryme = Convert.ToInt32(DataGrid1.Columns.Count);
> //Response.Write(tryme); //returns zero
> //dgCol1 = DataGrid1.Columns[0];
> //dgCol2 = DataGrid1.Columns[1];
> //DataGrid1.Columns.AddAt(0,dgCol2);
> //DataGrid1.Columns.AddAt(1,dgCol1);
>
> DataGrid1.DataBind();
>
> However, DataGrid1.Columns.Count returns zero. How come? A DataGrid
> with 8 columns is displayed normally.
Tim, the problem you are having is because the DataGrid's Columns
collection is not build up until *after* the data is bound to the grid
(that is, after the call to the DataBind() method).
Why can't you just reorder the BoundColumns in the <Columns> section, or
(if you're using AutoGenerateColumns=False), why can't you just
reorder the fields in your SQL query?
--
Scott Mitchell
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com
* When you think ASP, think 4GuysFromRolla.com!