swapping columns on ItemDataBoundEventHandler

T

Tim

Hi,

In the below code, a count of the DataGrid1.Columns yields zero
columns even after the ItemDataBound event is raised; otherwise,
DataGrid1.DataBind() works fine if I comment out
ItemDataBoundEventHandler as a datagrid with 8 columns and 20 rows is
rendered. In the GetTable(OleDBDataReader) function, I take a dataset
and append a column that displays the row- count at the very front of
the datagrid. I want to swap this row-count column with the first
column of the dataset.

....
DataSet ds = new DataSet();
ds.Tables.Add(this.GetTable(dr));
DataGrid1.DataSource = ds.Tables[0];

DataGrid1.DataBind();

}

void ItemDataBoundEventHandler(object sender, DataGridItemEventArgs e)
{
DataGridColumn dgCol1;
DataGridColumn dgCol2;

dgCol1 = DataGrid1.Columns[0];
dgCol2 = DataGrid1.Columns[1];
DataGrid1.Columns.AddAt(0,dgCol2);
DataGrid1.Columns.AddAt(1,dgCol1);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top