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

ClientSide sorting

1 Answer 23 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sitefinitysteve
Top achievements
Rank 2
Veteran
sitefinitysteve asked on 21 Jun 2010, 04:40 PM
How do you go about applying the sortExpression to a Linq Dataset created by OpenAccess?

This is how I'm doing it, but is there an easier way?
        if (sortExpression.Count > 0) { 
            switch (sortExpression[0].FieldName.ToLower()) { 
                case "alias"
                    if (sortExpression[0].SortOrder == GridSortOrder.Ascending) 
                        approvers = approvers.OrderBy(x => x.Alias).ToList(); 
                    else 
                        approvers = approvers.OrderByDescending(x => x.Alias).ToList(); 
                    break
                case "approvername"
                    if (sortExpression[0].SortOrder == GridSortOrder.Ascending) 
                        approvers = approvers.OrderBy(x => x.ApproverName).ToList(); 
                    else 
                        approvers = approvers.OrderByDescending(x => x.ApproverName).ToList(); 
                    break
                case "approveremail"
                    if (sortExpression[0].SortOrder == GridSortOrder.Ascending) 
                        approvers = approvers.OrderBy(x => x.ApproverEmail).ToList(); 
                    else 
                        approvers = approvers.OrderByDescending(x => x.ApproverEmail).ToList(); 
                    break
            } 
        } 

1 Answer, 1 is accepted

Sort by
0
BaiH
Top achievements
Rank 1
answered on 24 Jun 2010, 09:45 AM
You may try Dynamic Linq library ->
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

--BH
Tags
Grid
Asked by
sitefinitysteve
Top achievements
Rank 2
Veteran
Answers by
BaiH
Top achievements
Rank 1
Share this question
or