[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2013-05-10
2
Medium Priority
?
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

649 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