MvcContrib Grid Sorting?

The OrderBy extension method takes a delegate for getting the sort key, not a column and direction. So this line: listOfRfidTags = listOfRfidTags. OrderBy(sort.

Column, sort. Direction) needs to look something like this: listOfRfidTags = listOfRfidTags. OrderBy(r => r.

SomeProperty) (or OrderByDescending depending on the sort. Direction). The trouble is that SomeProperty can't be determined at compile time because you want it to come from sort.Column.

This means that if you want to use LINQ then you'll probably need to use Dynamic LINQ or Reflection to extract the property you want to sort on e. G PropertyInfo property = typeof(RfidTag). GetProperty(sort.

Column); listOfRfidTags = listOfRfidTags. OrderBy(r => property. GetValue(r)) However, since you are using LightSpeed as your ORM, you can bypass LINQ and use the core API, which does allow dynamic column names: Order order = Order.By(sort.

Column); if (sort. Direction == SortDirection. Descending)) order = order.Descending(); IList listOfRfidTags = uow.

Find(new Query { Order = order }) This has the side benefit that the sorting will happen on the database instead of in the Web application.

The OrderBy extension method takes a delegate for getting the sort key, not a column and direction. So this line: listOfRfidTags = listOfRfidTags. OrderBy(sort.

Column, sort. Direction); needs to look something like this: listOfRfidTags = listOfRfidTags. OrderBy(r => r.

SomeProperty); (or OrderByDescending depending on the sort. Direction). The trouble is that SomeProperty can't be determined at compile time because you want it to come from sort.Column.

This means that if you want to use LINQ then you'll probably need to use Dynamic LINQ or Reflection to extract the property you want to sort on e.g. PropertyInfo property = typeof(RfidTag). GetProperty(sort. Column); listOfRfidTags = listOfRfidTags.

OrderBy(r => property. GetValue(r)); However, since you are using LightSpeed as your ORM, you can bypass LINQ and use the core API, which does allow dynamic column names: Order order = Order.By(sort. Column); if (sort.

Direction == SortDirection. Descending)) order = order.Descending(); IList listOfRfidTags = uow. Find(new Query { Order = order }); This has the side benefit that the sorting will happen on the database instead of in the Web application.

This is great. I wrote programgood. Net/2011/04/08/SortingColumnsInMVC3.

Aspx based off stackoverflow. Com/questions/5417220/… – Dave Mateer Apr 8 at 2:40.

You are getting this compiling error because you are trying to use an OrderBy extension method that is only defined in MvcContrib and not in System.Linq. In order to fix it, you just need to use the following line: using MvcContrib. Sorting; And then you can use the OrderBy method as in your original code: listOfRfidTags = listOfRfidTags.

OrderBy(sort. Column, sort. Direction); Although itowlson answer works, he just reimplements what the OrderBy extension method in MvcContrib already does (see SortExtensions.Cs).

I had exact same problem and this fixed it for me – Doozer1979 Apr 24 at 15:18.

The OrderBy extension method takes a delegate for getting the sort key, not a column and direction. So this line.

You are getting this compiling error because you are trying to use an OrderBy extension method that is only defined in MvcContrib and not in System.Linq.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions