This is a migrated thread and some comments may be shown as answers.

RadGrid EditRow shifting

3 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jagat
Top achievements
Rank 1
Jagat asked on 18 Jul 2012, 04:50 PM
I'm displaying a set of records on the RadGrid. Below is the issue I'm facing.

1. User1 wants to edit one of the records by clicking edit button.
2. Meanwhile User2 inserts a new record. User1 didnt see this new record before clicking the edit button since no postback was issued and hence NeedDataSource was not fired.
3. For example:  When user1 clicks the edit button on the third row, a postback is issued, new record added by the user2 apperars as the first record in the grid. Now THIRD record is in edit mode. Actually 4th record should be in edit mode because of the new recorded added to the grid by User2.

I guess all this is happening because of the change in the row index when  new records are added.

How do I handle this issue?


3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 23 Jul 2012, 01:46 PM
Hello,

When you click "edit" on particular row, the data item that corresponds to this row will be edited. Insert/Edit items are based on index of the row and not index of the records.
If you like to avoid issue when the second user inserts a row, and the first user clicks on edit, and he gets different record in edit, you should sort the records in the database by inserted date, or by their unique ID which is auto incremented.

In this case if the second user adds new record, this record will be visible with last index. And regardless of which row is edited by the first user, it will always be correct.

Kind regards,
Vasil
the Telerik team
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 their blog feed now.
0
Jagat
Top achievements
Rank 1
answered on 13 Sep 2012, 08:11 PM
This wont work for us. we cannot always sort the records by the insert/update time.

Is there a way to put the row in editmode by the DataKeyValues?
0
Vasil
Telerik team
answered on 14 Sep 2012, 07:45 AM
Hello,

Yes, instead of the auto generated edit column. You can implement a template column with links that holds value bound from database.
Then on click of some of these links, loop thought all items in your grid, and place it in edit mode. Here is some pseudo-code:
int indexFound = 0;
foreach( item in yourGrid.MasterTableView.Items )
{
    if (item.DataItem["DataKeyName"] == YourDataKey)
        indexFound =item.index;
}
 
yourGrid.MasterTableView.Items[indexFound].Edit = true;

In this example, if you use paging, the record that you wish to edit, can be into the next page after second user inserts a record. If the record is in the next page, you will not be able to find and edit it.

You can use ClientSide editing, that will work without any problems in your scenario:
http://demos.telerik.com/aspnet-ajax/grid/examples/client/insertupdatedelete/defaultcs.aspx

Greetings,
Vasil
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Jagat
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Jagat
Top achievements
Rank 1
Share this question
or