S
Scott M.
When writing the update event handler for a web forms DataGrid, I am running
into a situation that is giving me quite the headache!
If a user has sorted the items in a DataGrid and then chooses to edit one of
the items, I have found that
e.Item.ItemIndex and e.Item.DataSetIndex will both return the same number
even when (in most cases) the item's number in the DataSet is different than
the item's number in the DataGrid.
I supsect that this has something to do with the fact that after a sort, the
grid is bound to a DataView, so when you ask for the e.Item.DataSetIndex,
you are really getting the index in the DataView.
This behavior does not occur when no sort has occured but the user has
changed from one page index to another. In those cases, the
e.Item.ItemIndex will return (correctly) the index of the item in the
DataGrid and e.Item.DataSetIndex will return (correctly) the index of the
item in the DataSet.
What I've had to do to solve the problem when a grid has sorting and paging
turned on is to loop through the DataSet numerically, looking for records
that have the same primary key value in the DataSet as the one being edited.
This works, but there must be a better (more effieicent) way.
Has anyone else run into this? What do you suggest? Why doesn't
"e.Item.DataSetIndex" always produce the value it implies it produces?
Thanks!
into a situation that is giving me quite the headache!
If a user has sorted the items in a DataGrid and then chooses to edit one of
the items, I have found that
e.Item.ItemIndex and e.Item.DataSetIndex will both return the same number
even when (in most cases) the item's number in the DataSet is different than
the item's number in the DataGrid.
I supsect that this has something to do with the fact that after a sort, the
grid is bound to a DataView, so when you ask for the e.Item.DataSetIndex,
you are really getting the index in the DataView.
This behavior does not occur when no sort has occured but the user has
changed from one page index to another. In those cases, the
e.Item.ItemIndex will return (correctly) the index of the item in the
DataGrid and e.Item.DataSetIndex will return (correctly) the index of the
item in the DataSet.
What I've had to do to solve the problem when a grid has sorting and paging
turned on is to loop through the DataSet numerically, looking for records
that have the same primary key value in the DataSet as the one being edited.
This works, but there must be a better (more effieicent) way.
Has anyone else run into this? What do you suggest? Why doesn't
"e.Item.DataSetIndex" always produce the value it implies it produces?
Thanks!