14

This may be a silly question but I was writing a quick test page and realised that I didn't know how to bind an array or ArrayList of strings, for example, to an ASP.NET Repeater.

I experimented a bit.

    <asp:Repeater ID="rptImages" runat="server">
        <HeaderTemplate>
            <h3>Items</h3>
        </HeaderTemplate>
        <ItemTemplate>
            <p style="background-color:Black;color:White"><%#Eval(Container.DataItem.ToString())%></p>
        </ItemTemplate>
        <FooterTemplate>
            <h4>End of Items</h4>
        </FooterTemplate>
    </asp:Repeater>

Am I being completely stupid? I've only really used it for collections of objects with properties.

Rob Stevenson-Leggett
  • 35,279
  • 21
  • 87
  • 141

1 Answers1

37

hoho ...

<%# Container.DataItem %>
  • @downvoter care to elaborate so that I can fix my answer? –  Dec 03 '15 at 12:57
  • What a terrible response. How come this have so many upvotes? – Pedro Rodrigues Jul 29 '20 at 08:45
  • @PedroRodrigues Instead of ranting without reasoning, you could provide a better solution - it would be helpful for the community to see better and up to date approaches, or to show the downsides of the solution! Also keep in mind, that this answer was written over 11 years ago (from your comment), and target ASP.NET 2.0 (WebForms only, and good ol' asmx-times). –  Jan 29 '21 at 21:55