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
Last Modified: 2010-04-23
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.

Question by:a76608
    LVL 6

    Accepted 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


    Author Comment

    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.


    Author Comment

    It worked!

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now