C
chotch
Hello,
I am having a spot of trouble with binding a DataTable to a DataGrid.
My problem originates after I have created the DataTable and DataGrid.
I present the grid to the user with the options to move rows up or
down. When a user selects one of these, I get the DataTable from the
session, rearrange the rows, and attempt to rebind the DataGrid to the
DataTable. This is when the problem occurs, and the DataGrid messes up
the order of the rows, even when the DataTable has the correct Data.
Has anyone encountered a problem like this? All my other DataGrid code
works fine.
Thanks in advance to anyone who takes time to respond!
Here is a little snippit:
int toItemIndex = to.ItemIndex;
int fromItemIndex = from.ItemIndex;
DataRow drFrom = conditionsTable.NewRow();
DataRow drTo = conditionsTable.NewRow();
drFrom["fields_id"] = from.Cells[9].Text;
drFrom["label"] = from.Cells[2].Text;
drTo["fields_id"] = to.Cells[9].Text;
drTo["label"] = to.Cells[2].Text;
//rearrange the order of the rows
conditionsTable.Rows.RemoveAt(toItemIndex);
conditionsTable.Rows.InsertAt(drFrom,toItemIndex);
conditionsTable.Rows.RemoveAt(fromItemIndex);
conditionsTable.Rows.InsertAt(drTo,fromItemIndex);
where.DataSource = conditionsTable.DefaultView;
where.DataBind();
I am having a spot of trouble with binding a DataTable to a DataGrid.
My problem originates after I have created the DataTable and DataGrid.
I present the grid to the user with the options to move rows up or
down. When a user selects one of these, I get the DataTable from the
session, rearrange the rows, and attempt to rebind the DataGrid to the
DataTable. This is when the problem occurs, and the DataGrid messes up
the order of the rows, even when the DataTable has the correct Data.
Has anyone encountered a problem like this? All my other DataGrid code
works fine.
Thanks in advance to anyone who takes time to respond!
Here is a little snippit:
int toItemIndex = to.ItemIndex;
int fromItemIndex = from.ItemIndex;
DataRow drFrom = conditionsTable.NewRow();
DataRow drTo = conditionsTable.NewRow();
drFrom["fields_id"] = from.Cells[9].Text;
drFrom["label"] = from.Cells[2].Text;
drTo["fields_id"] = to.Cells[9].Text;
drTo["label"] = to.Cells[2].Text;
//rearrange the order of the rows
conditionsTable.Rows.RemoveAt(toItemIndex);
conditionsTable.Rows.InsertAt(drFrom,toItemIndex);
conditionsTable.Rows.RemoveAt(fromItemIndex);
conditionsTable.Rows.InsertAt(drTo,fromItemIndex);
where.DataSource = conditionsTable.DefaultView;
where.DataBind();