How to get Child Pages by parent pageID or PageTitile

Posted by Community Admin on 04-Aug-2018 07:31

How to get Child Pages by parent pageID or PageTitile

All Replies

Posted by Community Admin on 25-Aug-2011 00:00

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

Posted by Community Admin on 29-Aug-2011 00:00

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

This thread is closed