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

Sorting Reorders Rows But Not EditMode

5 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 28 May 2011, 01:21 AM
I have a RadGrid that will have 0 or more individual rows editable at any time.

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

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 May 2011, 06:00 AM
Hello John,

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.
0
John
Top achievements
Rank 1
answered on 31 May 2011, 05:50 PM
Hi 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

0
Tsvetina
Telerik team
answered on 06 Jun 2011, 07:12 AM
Hello 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.

0
John
Top achievements
Rank 1
answered on 06 Jun 2011, 06:54 PM
Unless there is something I am missing, this won't work.  The PreRender event occurs after the ItemDataBound event.  I need to have the Edit mode set before the ItemDataBound event so the ItemDataBound event can load the appropriate control (it is a Template Column with a separate text box for each mode, Edit, Insert and Regular).

Thanks,

John
0
Tsvetina
Telerik team
answered on 07 Jun 2011, 12:23 PM
Hello 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.

Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
John
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or