Solved

How force a repeater to do something after every x number of items

Posted on 2013-05-10
2
552 Views
Last Modified: 2013-05-10
I have a repeater and I want to add a closing div/opening div after every 4 items.

At the moment, its only working when the number of items is 4

 if (itemRow == 4)

Open in new window


But I want it to do the same with 8, 12, 16, 20, 24, 28, etc items (any number divisible by 4) please


ASPX
<anthem:Repeater ID="rptDestinationInfo" runat="server" OnItemDataBound="rptDestinationInfo_ItemDataBound" AutoUpdateAfterCallBack="true" >
                            
                            <ItemTemplate>
                   
                            
                                    <div>
                                   
                                    <a href='<%#Eval("Name").ToString().ToQueryString() %>'></a>
                                   
                                    
                                    </div>
                                    <asp:Literal runat="server" ID="ltr1"></asp:Literal>
                        </ItemTemplate>
                            
                           
                            </anthem:Repeater>

Open in new window


CS
protected void loopRepeater()
        {

            int itemRow = 1;

            foreach (RepeaterItem item in rptDestinationInfo.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    if (itemRow == 4)
                    {
                        Literal ltr1 = item.FindControl("ltr1") as Literal;
                        if (ltr1 != null)
                        {
                            ltr1.Text = "<br /></div><div class='row'>";
                        }
                    }
                    itemRow++;
                }
            }

        }

Open in new window

0
Comment
Question by:aliciabutler
  • 2
2 Comments
 

Accepted Solution

by:
aliciabutler earned 0 total points
ID: 39154882
I fixed problem myself but here is the answer in-case anyone else needs it

Instead of

itemRow == 4

Open in new window


use

if (itemRow % 4 == 0)

Open in new window


Which basically divides the itemRow value by 4 and if the remainder left over is 0, then it adds my code to the literal.
0
 

Author Closing Comment

by:aliciabutler
ID: 39154884
Fixed myself
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question