Get each child item and display it

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error Get each child item and display it on this date .

Lets say I have a parent item and three child items in sitecore cms


I want to loop through all child items and display them using their individual sublayouts.

Is this possible and what do I need to do to achieve this.

At the moment, I can display one item in one placeholder, I am thinking of using a repeater to do this.

What are my best options? Is this actually possible? Are there any draw backs with the method you may suggest to me?


You can accomplish this by using the <sc:sublayout ... /> control from Sitecore.

First, you need to make each sublayout for those access a DataSource item. Here is sample code I’ve blogged on the topic.

Next, you need to repeat over the children and bind them to the sublayout control while passing each item in as the DataSource:


<asp:Repeater ID="myRepeater" OnItemDataBound="myRepeater_ItemDataBound" runat="server">
    <sc:sublayout ID="scSublayout" Path="path/to/your/sublayout/file.ascx" runat="server" />


// in the Page_Load
myRepeater.DataSource = homeItem.GetChildren();

protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    var scSublayout = e.Item.FindControl("scSublayout") as Sitecore.Web.UI.WebControls.Sublayout;
    if (scSublayout != null)
        scSublayout.DataSource = ((Sitecore.Data.Items.Item)e.Item.DataItem).ID.ToString();