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

[Solved] How to Do multiColumn Sorting programatically

2 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Liji Jose
Top achievements
Rank 1
Liji Jose asked on 09 Feb 2010, 06:32 AM
I could do Multi Column Sorting , by setting clicking the Column header s , but i want to do it Programatically without clicking the RadGrid Column headers ..

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Feb 2010, 11:39 AM
Hi,

You can manipulate the grid sort programmatically by creating instances of the GridSortExpression class and adding them to the SortExpressions collection.When the grid is first loaded on the page, it is sorted based on the GridSortExpression objects in the SortExpressions collection. If the SortExpressions collection contains multiple GridSortExpression objects, the table view is sorted first by the first GridSortExpression in the collection, then by the second GridSortExpression in the collection, and so on.

C#
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        if (!IsPostBack) 
        { 
            GridSortExpression expression = new GridSortExpression(); 
            expression.FieldName = "ContactName"
            expression.SortOrder = GridSortOrder.Descending; 
            RadGrid1.MasterTableView.SortExpressions.AddSortExpression(expression); 
            GridSortExpression expression1 = new GridSortExpression(); 
            expression1.FieldName = "CustomerID"
            expression1.SortOrder = GridSortOrder.Descending; 
            RadGrid1.MasterTableView.SortExpressions.AddSortExpression(expression1); 
            RadGrid1.MasterTableView.Rebind(); 
        } 
    } 


Thanks,
Shinu
0
Liji Jose
Top achievements
Rank 1
answered on 09 Feb 2010, 12:00 PM
Thank you very Much ,for your reply  :)
Tags
Grid
Asked by
Liji Jose
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Liji Jose
Top achievements
Rank 1
Share this question
or