Insert HTML tag every 3rd item in Repeater

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

Any ideas?

Thanks!
cmushaunAsked:
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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)
            BindData(10);
    }
    private void BindData(int testDataCount)
    {
        var TestData =
                System.Linq.Enumerable.Range(1, testDataCount)
                .Select(i => new
                {
                    ID = i,
                });
        this.rptDataTest.DataSource = TestData;
        this.rptDataTest.DataBind();
    }
</script>
</head>

<body>

<form id="form1" runat="server">
<asp:Repeater ID="rptDataTest" runat="server">
    <ItemTemplate>
    <% 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() %>
        <% } %>
    </ItemTemplate>
</asp:Repeater>
     
</form>

</body>

</html>

Open in new window

0
 
cmushaunAuthor Commented:
Thanks---I'll try this and let you know!
0
 
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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' does not contain a property with the name 'Author'.
0
 
cmushaunAuthor Commented:
Actually, got it! Thanks a lot!
0
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.