Selecting Wrong Index on Ajaxified RadGrid

6 posts, 0 answers
  1. Mark
    Mark avatar
    79 posts
    Member since:
    Apr 2007

    Posted 26 Sep 2008 Link to this post

    I've got a RadGrid inside of a Rad AjaxPanel.  When I click to edit a row, the radgrid databinds (AJAX) and then enters edit mode.

    So if I load the page, and then another user creates a new record, and then I click edit on the first record (in my grid), the grid databinds, switches to edit mode and index 0 is selected (which is the newly created record...not the original record I clicked on).

    Any thoughts on this?
  2. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 29 Sep 2008 Link to this post

    Hi mjhufford,

    This behavior basically depends on the way the control is databound. Can you please post the control declaration, or better yet open a formal support ticket, and supply a working project, demonstrating the glitch for further review?

    Kind regards,
    Yavor
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eric
    Eric avatar
    5 posts
    Member since:
    Jun 2012

    Posted 21 Aug 2013 Link to this post

    Was this issue ever resolved? I am having the same problem.

    When the edit command is called on the grid, the needdatasource event is called before the custom editing usercontrol is loaded.

    This is a problem when one or more rows have been added to the datasource and the grid has not been refreshed.

    The grid is updated adding an extra row (and moving the selected row down in the grid) and the DataItem which populates the edit usercontrol fields pulls back the newer row in the grid.

    This results in an editing form being pulled back for an item the user did not select.
  5. Martin
    Admin
    Martin avatar
    811 posts

    Posted 26 Aug 2013 Link to this post

    Hello Eric,

    If I understand the problem correctly, the issue is described in the steps bellow:

    1. RadGrid displays 3 items with ID 1,2 and 3 respectively. Two users request the page and are presented with the same RadGrid and items ordered in the same way.
    2. One of the users (say User1) edits and updates an item and because of the data changes, this item is no longer be presented on the same place in the grid. Lets say item with ID=1 is edited and updated which causes it to be shown on the second or third place for the user who edited it.
    3. Then other user (User2) still sees the initial order of the items because he requested the page before the changes. Now he tries to edit the same item (ID1). However instead the ID1 item, RadGrid puts either ID2 or ID3 item into edit mode.

    Note that this behavior is expected and to prove that you can try it with a standard GridView control. The problem is that the RadGrid(GridView) control does not know that the item User2 tries to edit is already edited and is no longer positioned on the same place. All the control tries to do is to edit an item with the same index. But since the item's index is already changed (note that the item could even be deleted) the control just puts in edit mode the new item that have the same index.

    In case the issue is different or any further assistance is needed, please consider opening a formal support ticket and send me a small runnable demo demonstrating the scenario you have.

    I hope this helps.

    Regards,
    Martin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Eric
    Eric avatar
    5 posts
    Member since:
    Jun 2012

    Posted 26 Aug 2013 Link to this post

    Thanks for the response. Your description of events is mostly correct. The main difference is the grid is displaying the items in reverse order ID 3,2,1. And the change is an addition of ID 4. So, if the user refreshed the page ID 4,3,2,1 would be displayed. 

    So, when the change happens before an edit they expect ID 3 but get ID 4.

    The solution I see would be if I could have events for before and after the refresh and programmatically assign the item based on the unique id. I have found the OnEditCommand which calls before the refresh and finds the correct item.

    Now I need to figure out how to set the data item based on the saved ID. I'm looking at setting it at the end of the OnNeedDataSource command. But I need to figure out what value I need to set so the correct item is selected.


  7. Martin
    Admin
    Martin avatar
    811 posts

    Posted 29 Aug 2013 Link to this post

    Hello Eric,

    First I want to emphasize that the behavior you try to accomplish is not supported out of the box due to the reasons I have enumerated in my previous post. Once again note that the standard GridView control behaves the exact same way as RadGrid.

    I am attaching a small sample project that demonstrates one approach you can follow to workaround the problem. Note that the code is not universal and its only purpose is to show the flow you could follow.

    As shown in the project, the desired functionality can be implemented manually, but it requires an additional rebind of RadGrid (one binding is needed to get the refreshed data, and one to put the item in edit mode after you find it in the refreshed data). In addition the implementation logic will differ depending on the scenario you have. Specifics like the way you bind your grid (DataSource control, NeedDataSource event etc) and the edit mode you use (InPlace, Forms, Tempate etc.) may require significant changes in the code. Also, if you have a scenario with paging, sorting, filtering or other functionality that reorders the items, you may hit the case where the item you try to put in edit mode is not in the currently displayed page. In this case it would be up to you to decide which item to put into edit mode.

    I hope this helps.

    Regards,
    Martin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017