Use a combination of Literal, Repeater PreRender event, and % Operator.
Here's how the aspx code should look like:
<asp:Repeater ID="DatesRepeater" runat="server" OnItemDataBound="DatesRepeater_ItemDataBound"
OnPreRender="DatesRepeater_PreRender">
<ItemTemplate>
<asp:Literal ID="ltDivPrefix" runat="server"></asp:Literal>
<asp:HiddenField runat="server" ID="eventID" />
<p><asp:CheckBox runat="server" ID="eventDateCheckbox" /></p>
<asp:Literal ID="ltDivSuffix" runat="server"></asp:Literal>
</ItemTemplate>
</asp:Repeater>
The expected result is the following:
- The text of
ltDivPrefix
will be<div class="column">
for nth item where n % 5 equals 0, otherwise it will be empty. - The text of
ltDivSuffix
will be</div>
for nth item where n % 5 equals 4, or n is the last index, otherwise it will be empty.
The total number of items can be obtained in PreRender
event, so do a looping through the Repeater items and set the text of ltDivPrefix
and ltDivSuffix
according to the item index:
protected void DatesRepeater_PreRender(object sender, EventArgs e)
{
for (int i = 0; i < DatesRepeater.Items.Count; i++)
{
Literal ltDivPrefix = (Literal)DatesRepeater.Items[i].FindControl("ltDivPrefix");
Literal ltDivSuffix = (Literal)DatesRepeater.Items[i].FindControl("ltDivSuffix");
if ((i) % 5 == 0)
{
ltDivPrefix.Text = @"<div class=""column"">";
}
if ((i % 5 == 4) || (i == DatesRepeater.Items.Count - 1))
{
ltDivSuffix.Text = "</div>";
}
}
}