Try Now
More in this section

Forums / Sitefinity SDK / Iterating Page Controls in the Order they are displayed

Iterating Page Controls in the Order they are displayed

2 posts, 0 answered
  1. Shawn
    Shawn avatar
    1 posts
    27 Jun 2011
    18 Jul 2011
    Link to this post
    I'm trying to use the API to iterate over the controls on a page in the order in which they should be displayed. I'm using the following code:

    PageManager pManager = PageManager.GetManager();         
    PageData page = pManager.GetPageDataList().Where(pD => pD.Title == pageName).FirstOrDefault();

    foreach (var ctrl in page.Controls)
    //Do stuff here

    Unfortunately what I'm finding is that there seems to be no reason in the ordering of the control collection.  How can I determine what order the controls should appear on the page?

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    01 Feb 2016
    21 Jul 2011
    Link to this post
    Hello Shawn,

    Can you try something like this:
    var postsPageControl = currentPage.Controls.Cast<PageControl>().OrderBy(c=>c.PlaceHolder).ToList().Sort((x, y) => x.SiblingId.CompareTo(y.SiblingId));

    Radoslav Georgiev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

2 posts, 0 answered