I am setting EditMode in the NeedDataSource event with the line
RadGrid1.EditIndexes.Add(i);
for each appropriate row.
However, if the user sorts the rows, the rows are reordered but the EditMode status of each row does not follow the data. If row 3 was editable, then row 3 is still editable even though it has different data in it.
I tried moving RadGrid1.EditIndexes.Add(i) to different events and nothing worked.
I noticed that the only two events that I can find that occur after the actual sorting is ItemCreated and ItemDataBound. In those events, neither RadGrid1.EditIndexes.Add(i) or e.Item.Edit = true cause IsInEditMode to be true in ItemDataBound.
How can I set the EditModes correctly on rows after sorting has been done?
5 Answers, 1 is accepted

I suppose you are not getting the sorted data in Edit mode after sorting. If that is the requirement, here is the code that I tried which worked fine as expected in my end.
C#:
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
SqlConnection con1 =
new
SqlConnection(WebConfigurationManager.ConnectionStrings[
"NorthwindConnectionString1"
].ConnectionString);
SqlCommand cmd =
new
SqlCommand(
"SELECT top 5 * FROM [Customers]"
, con1);
SqlDataAdapter ad =
new
SqlDataAdapter(cmd);
DataSet ds =
new
DataSet();
ad.Fill(ds);
RadGrid2.DataSource = ds;
for
(
int
i = 0; i < RadGrid2.PageSize; i++)
{
RadGrid2.EditIndexes.Add(i);
}
}
Thanks,
Princy.

Try setting just one of the rows to edit mode and then click the column headers to sort. See if the editmode of that row follows that row as it moves position in the grid. The sorting happens several events after the NeedDataSource event.
You are setting all of the rows to edit mode so you can't really see if the editmode on each datarow moves with the row. This I already can do.
Thanks,
John
This happend because this approach is referencing the rows by index, the EditIndexes collection is not related to the data inside the rows. If you would like to keep a certain row in edit mode, you should try finding it by DataKeyValue and putting it to edit mode. The approach would be similar to our example for persisting row selection on sorting/paging/filtering:
Persisting the selected rows server-side on sorting/paging/filtering/grouping
Greetings,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Thanks,
John
When handling the edit mode of items, you would also need to rebind the grid after setting the items to go into edit mode. Setting edit mode cannot happen earlier because before ItemDataBound the DataKeyValues of the grid item are not populated.
Kind regards,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.