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

synchronise sorting with second grid

2 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 05 Mar 2009, 08:25 AM
In my application I have to synchronise sorting from the first grid with the second grid.

Both grid get the same data from the same datatable.

Now I need programm that if the user sorts one column in the first grid, the same column should be sorted in the second grid automaticly.

What is the way to go?

Christian

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Mar 2009, 10:44 AM
Hi Christian,

You can use the same SortCommand event for both the Grid and try the following code snippet in the SortCommand event to achieve the desired scenario.


ASPX:
 <telerik:RadGrid ID="RadGrid1" AllowSorting="true" OnNeedDataSource="RadGrid1_NeedDataSource" OnSortCommand="RadGrid1_SortCommand"
 ......... 
 
 <telerik:RadGrid ID="RadGrid2"  runat="server" OnNeedDataSource="RadGrid2_NeedDataSource" AllowSorting="True" OnSortCommand="RadGrid1_SortCommand"
              
              
             
              

CS:
  protected void RadGrid1_SortCommand(object source, GridSortCommandEventArgs e) 
    { 
        RadGrid Grid = (RadGrid)source; 
         
        GridSortExpression sortExp = new GridSortExpression(); 
        sortExp.FieldName = e.SortExpression; 
        sortExp.SortOrder=e.NewSortOrder; 
        if (Grid.ID == "RadGrid1"
        { 
            RadGrid2.MasterTableView.SortExpressions.AddSortExpression(sortExp); 
            RadGrid2.MasterTableView.Rebind(); 
        } 
        else if (Grid.ID == "RadGrid2"
        { 
            RadGrid1.MasterTableView.SortExpressions.AddSortExpression(sortExp); 
            RadGrid1.MasterTableView.Rebind(); 
        } 
    } 


Thanks
Shinu
0
Christian
Top achievements
Rank 1
answered on 05 Mar 2009, 12:03 PM
Hi Shinu,

thank you!

Please tell your boss that I'm very lucky with your support!

Christian
Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Christian
Top achievements
Rank 1
Share this question
or