Difficulty with repeater using asp.net webforms

1

I'm having trouble dynamically rendering data in a repeater in asp.net webforms . I feed datasource of repeater with database records, and in html, it needs to be enclosed with </div><div class="row"> tag every 4 records. Follow the html below for a better understanding.

<div>
     <div class="row">
         <div class="item"></div>
         <div class="item"></div>
         <div class="item"></div>
         <div class="item"></div>
     </div>
     <div class="row">
         <div class="item"></div>
         <div class="item"></div>
         <div class="item"></div>
         <div class="item"></div>
     </div>
</div>

My repeater asp.net code:

<asp:Repeater ID="Repeater1" runat="server">
     <ItemTemplate>
         <div class="item">....</div>
     </ItemTemplate>
</asp:Repeater>

The problem is that I do not know how to enter the end, and the start of the <div class="row"> tag every 4 times in repeater again.

    
asked by anonymous 21.01.2015 / 23:49

1 answer

1

Try something like this:

<asp:Repeater ID="Repeater1" runat="server">
     <ItemTemplate>
         <%# (Container.ItemIndex + 4) % 4 == 0 ? "<div class='row'>" : string.Empty %>
              <div class="item">....</div>
         <%# (Container.ItemIndex + 4) % 4 == 3 ? "</div>" : string.Empty %>
     </ItemTemplate>
</asp:Repeater>
    
22.01.2015 / 01:21