More in this section

Forums / Developing with Sitefinity / Sorting DateCreated CMSManagerGetPages

Sorting DateCreated CMSManagerGetPages

3 posts, 0 answered
  1. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    18 Jul 2007
    Link to this post
    Is there a way to sort the cms manager getpages IList by DateCreated? I created a simple comparer, but can't seem to cast the IList to an ArrayList in order to Get 'Er Done and IList itself does not support sort.

    Sincerely,

    Ben

  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    19 Jul 2007
    Link to this post
    Hello Ben,

    Sorting a generic list requires adapting the list to an ArrayList. You could use the Adapter method that creates an ArrayList wrapper around IList .Here's a class and method call that supports sorting a list by DateCreated value of its members.

    public class CustomComparer : IComparer

    {

      public int Compare(object x, object y)

      {

    return ((IPage)x).DateCreated.CompareTo(((IPage)y).DateCreated);

      }

    }

    ArrayList.Adapter(this.GetPages()).Sort(new CustomComparer());

    Hope this helps.

    Regards,
    Pepi
    the Telerik team



    Instantly find answers to your questions at the new Telerik Support Center
  3. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    19 Jul 2007
    Link to this post
    So simple! perfect!
Register for webinar
3 posts, 0 answered