I have a repeater on which I bind a list with 3 items. The databind() is called once, I have checked this using the debugger. I have some strange behavior here because the Repeater seems to walk through this list of items twice. Instead of the 3 items, I see the repeater bind everything twice.
/// <summary>
/// Handles the Load event of the Page control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected void Page_Load(object sender, EventArgs e)
{
Sitecore.Data.Items.Item contextItem = Sitecore.Context.Item;
Sitecore.Data.Fields.MultilistField thisSnippets = contextItem.Fields["snippets"];
List<Item>thisSnippetItems = thisSnippets.GetItems().ToList<Item>();
if (thisSnippetItems.Count > 0)
{
rptListRenderer.DataSource = thisSnippetItems;
rptListRenderer.DataBind();
}
}
/// <summary>
/// Handles the ItemDataBound event of the rptListRenderer control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param>
private void rptListRenderer_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Item dataItem = (Item)e.Item.DataItem;
System.Web.UI.WebControls.PlaceHolder phLiContent = (System.Web.UI.WebControls.PlaceHolder)e.Item.FindControl("phLiContent");
if (phLiContent != null)
{
Sitecore.Data.Items.DeviceItem listItemDevice = Sitecore.Context.Database.Resources.Devices["List item"];
RenderingReference[] renderings = dataItem.Visualization.GetRenderings(listItemDevice, false);
foreach (RenderingReference rendering in renderings)
{
string strDataSource = dataItem.ID.ToString();
rendering.Settings.DataSource = strDataSource;
Sublayout thisControl = (Sublayout)rendering.RenderingItem.GetControl(rendering.Settings);
if (blockCounter == 0)
{
thisControl.Parameters = "class=snippetColHomeFirst";
}
else
{
thisControl.Parameters = "class=";
}
phLiContent.Controls.Add(thisControl);
blockCounter++;
}
}
}
repeater html:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="hpSnippetList.ascx.cs" Inherits="Snippets.Sublayouts.hpSnippetList" %>
<%@ Register TagPrefix="sc" Namespace="Sitecore.Web.UI.WebControls" Assembly="Sitecore.Kernel" %>
<asp:repeater id="rptListRenderer" runat="server" EnableTheming="false" EnableViewState="false">
<itemtemplate>
<asp:placeholder id="phLiContent" runat="server" />
</itemtemplate>
</asp:repeater>
Any suggestions on how this can be solved? Page load is called only once, databind() is only called once.