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

[Solved] get and set column sort order programatically

2 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 20 May 2013, 05:14 PM
Hi,

Our requirement is to maintain the status of the grid when user navigates from parent page to child page. So, when child page link in the grid is clicked, we are saving entire page state (dropdown list control selected values, grid sort, display of columns etc). Upon coming back from child page, we are assigning dropdown values back to controls from session and binding the grid to object that gets data from db based on dropdownlist control values. Then we are planning to set grid state (like sort order, display of columns etc)..

For this, when saving grid state, I need to loop thru columns and get col sort order. This code is out of radgrid events. I am doing this way:

foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
{
   if (col is GridBoundColumn)
     {
          GridBoundColumn gbc = col as GridBoundColumn;
           object sortOrder = gbc.SortExpression;
     }

}

I know that I sorted column. But SortExpression (if I mouse over SortExpression, is always empty).
Please let me know how to get the sort expression or sort order programatically and also how to set grid sort order.

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 20 May 2013, 06:38 PM
Hello,

Please try with below link/demo.

Grid - Persisting Grid Settings

Thanks,
Jayesh Goyani
0
Prathibarani
Top achievements
Rank 1
answered on 21 May 2013, 09:46 PM
Thank you Jayesh. The article helped.
Tags
Grid
Asked by
Prathibarani
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Prathibarani
Top achievements
Rank 1
Share this question
or