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

Forums / Developing with Sitefinity / How to get Child Pages by parent pageID or PageTitile

How to get Child Pages by parent pageID or PageTitile

2 posts, 0 answered
  1. Pravat
    Pravat avatar
    59 posts
    Registered:
    22 Jun 2010
    25 Aug 2011
    Link to this post
    Hi Team,
                  I am using Repeater control to bind parent page list and child page list in my custom navigation control.I am able to bind the parent pagelist by using below code
    protected void Page_Load(object sender, EventArgs e)
        {
            var myPageNode = App.WorkWith().Pages().LocatedIn(PageLocation.Frontend).Where(p => p.Parent.Id == SiteInitializer.FrontendRootNodeId).Get().ToList();
      
            repFooter.DataSource = myPageNode;
            repFooter.DataBind();
        }
      
        protected void repFooter_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                PageNode pg = (PageNode)e.Item.DataItem;
                HyperLink hlMainMenu = (HyperLink)e.Item.FindControl("hlMainMenu");
                hlMainMenu.Text = pg.Title;
                hlMainMenu.NavigateUrl = pg.GetFullUrl();
      
                Repeater repSubList = (Repeater)e.Item.FindControl("repSubList");
                 
                if (repSubList != null)
                {
                    repSubList.ItemDataBound += new RepeaterItemEventHandler(repSubList_ItemDataBound);
                }
               }
        }
    void repSubList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
    }



    How can i bind child node list in my childnode Repeater control? Please help me. this is urgent.

    Thanks & regards,
    Pravat Sharma

  2. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    29 Aug 2011
    Link to this post
    Hi Pravat,

    You can do the following:

    if (repSubList != null)
    {
        var mySubPageNode = App.WorkWith().Pages().LocatedIn(PageLocation.Frontend).Where(p => p.Parent.Id == pg.Id).Get().ToList();
        repSubList.ItemDataBound += new RepeaterItemEventHandler(repSubList_ItemDataBound);
        repSubList.DataSource = mySubPageNode;
        repSubList.DataBind();
    }

    Then you .ascx template might look like this:

    <asp:Repeater ID="repFooter" runat="server" OnItemDataBound="repFooter_ItemDataBound">
        <ItemTemplate>
            <asp:HyperLink ID="hlMainMenu" runat="server"></asp:HyperLink>
            <asp:Repeater ID="repSubList" runat="server">
                <ItemTemplate>
                    <asp:HyperLink ID="hlMainMenu" runat="server"></asp:HyperLink>
                </ItemTemplate>
            </asp:Repeater>
        </ItemTemplate>
    </asp:Repeater>

    This will create some sort of 2-level navigation hierarchy.

    All the best,
    Lubomir Velkov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

2 posts, 0 answered