• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • 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.

  • 2
1 Solution
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

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.

a76608Author Commented:
It worked!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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