Nate
Nate

Reputation: 30636

How do I bind an ASP.NET Repeater Control to an IList<String>?

I've never had to do this, but I'm binding a repeater to a generic list of Strings, and I'm not sure of the correct syntax.

If I was binding to an IList and myType had a property LayerName I'd use this:

<asp:Repeater ID="rptChecks" runat="server">
     <ItemTemplate>
          <input type="checkbox" id="<%#Eval("LayerName") %>"/>
     </ItemTemplate>
</asp:Repeater>

How can I do this when I'm only binding to a String which does not have any properties to use?

Upvotes: 4

Views: 4670

Answers (1)

Andrew Hare
Andrew Hare

Reputation: 351466

Try this:

<asp:Repeater ID="rptChecks" runat="server">
     <ItemTemplate>
          <input type="checkbox" id="<%# Container.DataItem %>"/>
     </ItemTemplate>
</asp:Repeater>

Upvotes: 12

Related Questions