1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Sort the IList output from CmsManager.GetPages()

Sort the IList output from CmsManager.GetPages()

5 posts, 1 answered
  1. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    14 Oct 2008
    Link to this post
    I need to be able to sort the output of this method by the order it is displayed in SiteFinity.

    I assume that this is the ORDINAL column... I noticed there is a overload of this method that i can do this... Can someone give me an example code for it because i have tried to use it an get nothing back in return when using the overload...

    IList pages = manager.GetPages(0, 999, "ORDINAL", System.ComponentModel.ListSortDirection.Ascending, out rowcount); 

    Is this the way to do it? And what am i doing wrong here?

    Nugs
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    15 Oct 2008
    Link to this post
    Hello Nugs,

    CmsPageInfo object has no column named Ordinal. If you want to sort pages by Ordinal you need to write a custom comparer class that implements IComparer interface like this:

    using System; 
    using System.Collections; 
    using System.Configuration; 
    using System.Data; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using Telerik.Cms; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
     
    public partial class SimpleMenu : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) 
            { 
                menu.DataSource = GetSource(); 
                menu.DataBind(); 
            } 
        } 
     
        private List<ICmsPage> GetSource() 
        { 
            CmsManager manager = new CmsManager(); 
            IList pages = manager.GetPages(); 
     
            List<ICmsPage> source = new List<ICmsPage>(); 
     
            foreach (ICmsPage page in pages) 
            { 
                if (page.PageType == CmsPageType.Group) 
                { 
                    source.Add(page); 
                } 
            } 
     
            CmsPageComarer comparer = new CmsPageComarer(); 
            source.Sort(comparer); 
     
            return source; 
        } 
     
        internal class CmsPageComarer : IComparer<ICmsPage> 
        { 
            #region IComparer<ICmsPage> Members 
     
            public int Compare(ICmsPage x, ICmsPage y) 
            { 
                return x.Ordinal.CompareTo(y.Ordinal); 
            } 
            #endregion 
        } 
     

    Do let us know if this helps.

    Kind regards,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    15 Oct 2008
    Link to this post
    What exactly do this do? I am not sure this is what i am looking for but will try it...

    I find it hard to believe that there is not order by column in the pages table. Am i looking at the wrong table here?

    I am looking at the SF_PAGEBASE table where it seems my site page structure is... In this table is a Ordinal column which i am guessing is the order pages are in the tree...

    I have another previous post on this subject (although it start out as a more general questions) http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bggkhg.aspx

    In this post i was advised to use the overload of GetPages() method, the overload apears to be there to allow me to sort the IList output... All i am trying to get here is the sort expersion to use that will give me the list ordered as it apears in the SiteFinity admin area...

    Nugs
  4. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    15 Oct 2008
    Link to this post
    Additionally, i am looking at the IList outputted by GetPages() and each item contains a property for Ordinal...

    Nugs
  5. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    15 Oct 2008
    Link to this post
    My sincerest apologies… I did not read your code solution close enough… This is the solution I was looking for and sorts this IList as I need it sorted…

    Thank you very much!

    Nugs
    Answered
Register for webinar
5 posts, 1 answered