Solved

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

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project

756 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