Sorting databound pages

Vote:
 

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

  

#55979
Dec 23, 2011 10:47
Vote:
 

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

#55980
Dec 23, 2011 10:54
Vote:
 

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 ;> 

 

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

should work.

#56113
Jan 05, 2012 14:33
Vote:
 

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! :)

#56157
Edited, Jan 09, 2012 16:27
Vote:
 

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

#56166
Jan 10, 2012 9:14
Vote:
 

thanks alot everyone.

#56206
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.