Insert HTML tag every 3rd item in Repeater

I have a repeater in C#/ website, and I need to insert a line of html (<div class="clear"></div>) after every third item.

Any ideas?

Who is Participating?
mcarbajalConnect With a Mentor Commented:

Here's a start.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ExpertsExchangeWebApplication._Default" %>
<%@ Import Namespace="System.Linq" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<script runat="server">
    int itemCount = 0;

    protected override void OnLoad(EventArgs e)
        if (!Page.IsPostBack)
    private void BindData(int testDataCount)
        var TestData =
                System.Linq.Enumerable.Range(1, testDataCount)
                .Select(i => new
                    ID = i,
        this.rptDataTest.DataSource = TestData;


<form id="form1" runat="server">
<asp:Repeater ID="rptDataTest" runat="server">
    <% itemCount += 1; %>
        <div>This is the record number <%# DataBinder.Eval(Container.DataItem, "ID") %></div>
        <% if (itemCount % 3 == 0) { %>
            <%= "Show an extra div here after item " + itemCount.ToString() %>
        <% } %>



Open in new window

cmushaunAuthor Commented:
Thanks---I'll try this and let you know!
cmushaunAuthor Commented:
Hi, Not sure how this works...  When I add this code, I am getting a Server Error (shown below) that the databinding does not contain a property of my already defined repeater:

DataBinding: '<>f__AnonymousType0`1[[System.Int32, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' does not contain a property with the name 'Author'.
cmushaunAuthor Commented:
Actually, got it! Thanks a lot!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.