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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.