Solved

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

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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

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…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 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