When clicking on the Edit button on a datagrid for inline editing, the incorrect row is set to edit mode
Posted on 2006-05-10
I have a dataset(populated by sql query) that is bound to a datagrid.
I have paging enabled and it is set to 10 rows per page.
I only allow for one row to be edited at a time.
When i click on the edit button, i have that row going into edit mode with the following code snippet in the datagrid_editcommand function:
datagrid1.EditItemIndex = e.item.itemindex
I then rebind the datagrid.
This works fine majority of the time, but i recently ran into an issue where the wrong row is in edit mode.
I know why it is happening. In between the time i originally loaded the datagrid and click on the edit button, new rows(for this example let's say 2 new rows have been inserted behind the scenes) have been inserted into the database.
So when i set edititemindex to e.item.itemindex, and rebind the datagrid with the same query, i now have 2 additional rows, and as a result, e.item.itemindex is wrong, and the row i really want to edit has moved down 2 spots.
I'm at a loss as to how to resolve.
Any help would be appreciated.