Sorting databound pages


Hey everyone! Im trying to sort pages of a certain pagetype on my episite but i've ran into trouble. What I want to do is to first load all my Pages of the PageType ContactCard into my SortingPage, which is of the PageType SortingPage. Since these ContactCard's is not located directly below the SortingPage in the EPiServer site tree, I have a property on my SortingPage called "ContactCards to list", which just lets the editor pick what cards should show up in the list. Pretty straightforward there, now onto the harder part (Atleast for me :)):

At the top of my SortingPage I've got a DropDownList that looks like this:






<inputtype="Submit"value="Sort Contacts"runat="server"class="SubmitSort"/>

So what i'd like to know is how does one connect these sorting criterias to the Pagetype on display on my SortingPage (ContactCard)? Since it's databound from another place on the site into my SortingPage, im having trouble figuring out (or to find any good blogposts about it) how to execute this properly. At this moment, all my SortingPage does is to run a webcontrol that takes care of providing the ContactCards (which works great!), now i'd like a good way, if possible, of sorting them on my SortingPage.

Any advice or helpful links is greatly apprechiated. Happy holidays!



Dec 23, 2011 10:47

What are you using to generate the list of pages? PageList? Repeater? For PageList you can use the SortOrder property (see: For Repeater you can use the Filter classes or Lambda.

Hope this helps.


Dec 23, 2011 10:54

Thanks! Sorted it out with the following:





          var b = Selection.SelectedItem;

          if (b.Value == "zip")


                    cards.RemoveAll(x => x.Zipcode == null);

                    cards.Sort(delegate(PageTypes.PageTypes.ContactCardPage f1, PageTypes.PageTypes.ContactCardPage f2)


              return f1.Zipcode.CompareTo(f2.Zipcode);




Could probably have made it alot more dandy with a switch (, but oh well ;> 


Jan 05, 2012 8:26
switch (Selection.SelectedValue) {
case "zip": cards = cards.OrderBy(c=>c.Zipcode); break;
case "someother": cards = cards.OrderBy(c=>c.Someother); break;

should work.

Jan 05, 2012 14:33

That did the trick, thanks a bunch! I added cards.RemoveAll(x => x.Zipcode == null); to remove all empty ones at first, but turns out I have to display the empty ones at the end of my sorting. Any ideas? Essentially:




-card without zipcode-


I cant find a good way to declare this. thanks! :)

Edited, Jan 09, 2012 16:27

cards.OrderBy(c => x.Zipcode != null ? c.Zipcode : avaluethatwillcomelast);

Jan 10, 2012 9:14

thanks alot everyone.

Jan 12, 2012 8:55
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.