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

setting sort order programmatically

2 Answers 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bgoldca
Top achievements
Rank 1
bgoldca asked on 18 Sep 2009, 06:30 PM
I'm creating a grid dynamically in my c# code by adding columns like this:

GridBoundColumn

 

boundColumn = new GridBoundColumn();

 

TargetGrid.MasterTableView.Columns.Add(boundColumn);

After I've added all of the columns I need to set the sort order programmatically. So let's say I add 3 columns: ID, name and address. Now I need to set the grid to sort ascending on Name. How can I do that?

Thanks in advance!
Ben

2 Answers, 1 is accepted

Sort by
0
bgoldca
Top achievements
Rank 1
answered on 18 Sep 2009, 08:47 PM
Here's an update - I'm half-way there. I've figured out how to set the sort order using MasterTableView.SortExpressions.AddSortExpression() and the grid sorts correctly, but the sort direction icon doesn't appear. How can I get that to appear after programmatically sorting?

Thanks in advance,
Ben

0
Nikolay Rusev
Telerik team
answered on 21 Sep 2009, 06:12 AM
Hello Ben,

The following line should do the trick for you:
 RadGrid1.MasterTableView.SortExpressions.AddSortExpression(new GridSortExpression()   
            {   
                FieldName = "col1", SortOrder = GridSortOrder.Descending   
            }); 

Kind regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
bgoldca
Top achievements
Rank 1
Answers by
bgoldca
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or