What are you using to generate the list of pages? PageList? Repeater? For PageList you can use the SortOrder property (see: http://www.frederikvig.com/2009/07/episerver-web-controls-pagelist/). For Repeater you can use the Filter classes or Lambda.
Hope this helps.
Frederik
Thanks! Sorted it out with the following:
if
(Page.IsPostBack)
{
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 (http://msdn.microsoft.com/en-us/library/06tc147t(v=VS.80).aspx), but oh well ;>
switch (Selection.SelectedValue) {
case "zip": cards = cards.OrderBy(c=>c.Zipcode); break;
case "someother": cards = cards.OrderBy(c=>c.Someother); break;
}
should work.
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:
-zipcode-
-zipcode-
-zipcode-
-card without zipcode-
I cant find a good way to declare this. thanks! :)
cards.OrderBy(c => x.Zipcode != null ? c.Zipcode : avaluethatwillcomelast);
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:
<asp:dropdownlistrunat="server"ID="Selection"CssClass="Selection">
<asp:listitem>Alphabetically</asp:listitem>
<asp:listitem>Zipcode</asp:listitem>
<asp:listitem>Town</asp:listitem>
</asp:dropdownlist>
<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!
Robin