Difficulty with Repeater using Asp.net webforms

Asked

Viewed 143 times

1

I’m having trouble dynamically rendering data into one redepeater in the Asp.net webforms. I feed the datasource from the database record, and in html, I need to include the tag </div><div class="row"> every 4 records. Follow the html below for 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 Asp.net Repeater code:

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

The problem is that I don’t know how to insert the end, and the tag start again <div class="row"> every 4 records in the redepeater.

1 answer

1


Try something like that:

<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>
  • Thanks @iuristona, it worked, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.