• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

When clicking on the Edit button on a datagrid for inline editing, the incorrect row is set to edit mode

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.



0
a76608
Asked:
a76608
  • 2
1 Solution
 
SandeepRRCommented:
Hi a76608,
          As per your  explanation what i understood is that u are running the query for filling the datagrid everytime when user click on the select button,

Now you can do one thing like instead of requering the database for every select button click, u store the dataset loaded in datagrid first time in the Sesssion object and in the selected index change, u just bind the datagrid with the dataset in the session object

In the main event where u populate the grid for first time
Session("Dataset")=ur dataset object

and ---------dataset object = Session("Dataset")-------- in the selected index change event
and use this dtaset to datagrid source and then bind the datagrid


Regards
SandeepRR
0
 
a76608Author Commented:
I was so focused on finding the correct row in the updated dataset, it did not even occur to me to save the original dataset in the session object.
I'll give this a try today and let you know what happens.
Thanks.

0
 
a76608Author Commented:
It worked!
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now