Concurrency issues with GridView

Last post 10-03-2006 4:41 PM by jdcrutchley. 3 replies.

Sort Posts:

  • Concurrency issues with GridView

    09-15-2006, 7:26 PM

    Here is a major concurrency issue I've found with the GridView that hopefully someone has come up with a good solution to, because I haven't yet...

    When any kind of event fires on a control within one of the rows, it is tied to that row by row number.  So if I have two users looking at the same list and one guy deletes the third record in the list, then the other guy goes to delete the fifth record in the list, the second guy actually ends up deleting the sixth record in his list since that's not the fifth record thanks to the first delete!  I've tried using a TemplateField and manually building a LinkButton with the CommandArgument set to the ID of the data object, but it seems that the CommandArgument isn't actually sent up with the request, but instead populated when the event happens - based on the row number again, so again you get the wrong row.

    How can something like this be prevented?  I've searched all over the place and can't find any solutions that don't require so much hackery it's not even worth using the damned GridView.  And no, I don't want to store the viewstate for the entire GridView just so I can detect when it's changed - that's a rediculous amount of data to send back and forth just to fix this.

     Any ideas?

     

     

    -- jdc
  • Re: Concurrency issues with GridView

    09-18-2006, 3:23 AM
    Answer
    • Loading...
    • rexlin
    • Joined on 07-17-2006, 8:43 AM
    • Posts 1,751

    Hi,jdcrutchley:

    You may refer this tutorial:

    http://www.asp.net/learn/dataaccess/tutorial21cs.aspx?tabid=63



    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    This posting is provided "AS IS" with on warranties, and confers no rights.
  • Re: Concurrency issues with GridView

    09-18-2006, 1:23 PM
    rexlin:

    Hi,jdcrutchley:

    You may refer this tutorial:

    http://www.asp.net/learn/dataaccess/tutorial21cs.aspx?tabid=63

    Thanks rexlin, but that article misses the point entirely.  That kind of "baked-in" concurrency only works if you have viewstate enabled for the GridView.  If you happen to have the code for that tutorial, fire it up, load the concurrency page, and take a look at your page source - look at that big, bloated ViewState!  Now disable ViewState for that page and try the following:

    1.  Bring up two browsers, both showing that page.

    2.  Delete an item in Browser #1 - it should refresh showing that item gone.

    3.  Go to Browser #2, you should still see the original item there since you didn't refresh the page.  Without refreshing the page first, try to delete it.  You'll notice it happily deletes whatever record happened to come AFTER the one you intended to delete since the GridView is tracking that even by row #.

    My issue is that when ViewState is disabled for a GridView (which it almost always should be when you're dealing with a significant amount of data) the GridView loses it's mind when it comes to knowing which actual data item it's working with.  The argument that gets passed for ItemCommand events is a row number.  If the actual items (number or order) in the list have changed, it just acts on whatever item happens to be at that row at the time it gets loaded - which presents a problem in multi-user environments as well as if the user performs an action then immediately does a browser refresh.

    I've got an idea for a workaround though that lets have the GridView events use the data key instead of row number, which is the way it should have worked to begin with in my opinion...  Not to mention it'll let me handle concurrency based on a timestamp field in the database instead of having to track the pre and post values of every field in the record.  I'll post an example once I have it worked out.

     

    -- jdc
  • Re: Concurrency issues with GridView

    10-03-2006, 4:41 PM

    Forgot to link my workaround.  Here it is:  http://forums.asp.net/thread/1401397.aspx. Scott Mitchell has also given this some treatment on his blog at http://www.scottonwriting.net/sowBlog/ (the Oct. 3, 2006 entry) and has a workaround for the delete issue that allows for using the ObjectDataSource.  I haven't had a chance to test his solution since I've gone a route that doesn't use DataSources, but given Scott's knowlege of ASP.NET I'm sure it works.

    jdc

     

    -- jdc
Page 1 of 1 (4 items)