Solved

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

Posted on 2013-05-10
2
522 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now