I'm using an asp.net repeater to create a bunch of images. The image markup is all the same so the standard <ItemTemplate>
is fine.
However, I want to wrap K images in a div. Lets say I bind 25+ images to the repeater and I want 5 images per div. How do I go about conditionally creating the start and close tags for the div?
Is this a case better suited for a for loop.
This should work for you, with no need for anything in the code behind (other than binding the repeater..):
<asp:Repeater ID="repImages" runat="server">
<HeaderTemplate><div></HeaderTemplate>
<ItemTemplate>
<%# (Container.ItemIndex != 0 && Container.ItemIndex % 5 == 0) ? @"</div><div>" : string.Empty %>
<asp:Image ID="imgGallery" runat="server" ImageUrl='<%# /* your code here */ %>' />
</ItemTemplate>
<FooterTemplate></div></FooterTemplate>
</asp:Repeater>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With