Sort pages by two properties



I have a pagedatacollection... Right now im sorting this collection by "date" and then by "division" with FilterPropertySort... the following way:

new FilterPropertySort("Date", FilterSortDirection.Descending).Filter(KPages); 
new FilterPropertySort("Division").Filter(KPages); 

Somehow it seems like the later sorting is messing up the first sorting (in some cases)... The order by date is not fully maintained. I wonder if am doing this the wrong way maybe... How could/should I sort this collection in another way?


Oct 21, 2013 15:47

How about if you use OrderBy() and ThenBy() LINQ extension methods?


Oct 21, 2013 21:27

Okey... I've had a look at LINQ now and I feel a bit confused (I haven't used LINQ before). I tried the following

var alist = from p in DataFactory.Instance.GetChildren(aPage)
orderby p.Property["Date"]
select p;

rptList.DataSource = alist; 

I run into problems with the datasource at runtime (Err: At least one object must implement IComparable.). I'm using a repeater to display my list. If you have some "for dummies" example that I can learn from it would be great :) Have done a bit of searching on the subject and the links tend to lead me to places where I don't belong atm ;)

Oct 22, 2013 10:04

This error comes from the orderby statement and the p.Property["Date"]. If you trying to sort by publish date use that instead:

orderby p.StartPublish


Oct 22, 2013 10:09

Your right! The thing is, I'm not trying to sort it by publishdate... I wanna sort it by a property (Date) that describes when something is happening (DateTime). It should be possible right?

Oct 22, 2013 10:49

Yes, just cast it to DateTime.

orderby (DateTime)p.Property["Date"]


Oct 22, 2013 10:50

Hmm... I tried that earlier but get "Cannot convert type EPiServer.CorePropertyData" to "System.DateTime". Thank you for your replies :) Any ideas?

Oct 22, 2013 10:55
orderby (DateTime)p["Date"]


Oct 22, 2013 10:57

YES! Awesome :) Many thanks Frederik... Good to know for future use. Hope you have a real nice day now :)

Oct 22, 2013 11:02
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.