Repeater Controls

Repeater Controls

Repeater Controls

  • A data-bound container control that produces a list of individual item objects
  • Used to create custom lists from Sitecore items or other data
  • Binds to objects that are returned from a data source and displays them
  • Displays data formatted by templates and styles that you define

Notes

  • The following issues can occur when attempting to use ASP.NET controls to display Content Tree items:
    • Viewstate issues
    • Paging issues
  • The solution is to add an entry for the Repeater to the <typesThatShouldNotBeExpanded> section of the web.config file

Repeater Markup in ASCX file

  • <div style="font-weight: bold; width: 100%; clear: both">
    • <asp:Label ID="Label1" runat="server" />
  • </div>
  • <div style="font-size: x-small; width: 100%; clear: both">
    • <asp:Label ID="Label2" runat="server" />
    • <asp:Repeater ID="Repeater1" runat="server">      
  • <SeparatorTemplate>
    • <tr>
      • <td>----------<br /> </td>
    • </tr>
  • </SeparatorTemplate>  
  • <ItemTemplate>
    • <tr>
      • <td> <%# Container.DataItem %> <br /> </td>
    • </tr>
  • </ItemTemplate>
  • </asp:Repeater>
  • </div>

Repeater Controls C# User Control Code

if (!IsPostBack)

            {
                Sitecore.Data.Items.Item item = Sitecore.Context.Item;
                if (item == null) return;
                Sitecore.Data.Items.Item parent = item.Parent;
                if (parent == null) return;
                Sitecore.Collections.ChildList children = parent.GetChildren();
                if (children == null) return;
                Label1.Text = "C# User Control Real-time Output";
                string displayName = Sitecore.StringUtil.GetString(parent.DisplayName, parent.Name);
                //using &#58; for colon and &#160; for space
                Label2.Text = ("<p>Item&#58;&#160;" + "<b>" + displayName + "</b></p>");
  
                System.Collections.ArrayList items = new System.Collections.ArrayList();
                foreach (Sitecore.Data.Items.Item child in children)
                 {
                     if (child.Name.Contains("Control"))  
                            items.Add(child.DisplayName);
                 }
                Repeater1.DataSource = items;

                Repeater1.DataBind();

            }

Configuration Settings

  • <configuration>
    • <sitecore>
      • <rendering>
        • <typesThatShouldNotBeExpanded>

Sources