How can I bind a simple list of strings to a repeater?
Protected Sub Page_Load(sender As Object, e As System.EventArgs)
    'create sample data:
    Dim photos As New List(Of String)
    photos.Add("large1.jpeg")
    photos.Add("large2.jpeg")
    photos.Add("large3.jpeg")
    photos.Add("large4.jpeg")
    photos.Add("large5.jpeg")
    'bind data:
    Repeater1.DataSource = photos
    Repeater1.DataBind()
End Sub
The HTML is simply:
        <asp:Repeater ID="Repeater1" runat="server" ClientIDMode="Predictable">
            <HeaderTemplate><ul></HeaderTemplate>
            <FooterTemplate></ul></FooterTemplate>
            <SeparatorTemplate>
                <li>
                    <asp:Image ID="img_photo" runat="server" ImageUrl="<%# Container.DataItem %>" /></li>
            </SeparatorTemplate>
        </asp:Repeater>
The value from Container.DataItem is always empty.
Any ideas?
Change <SeparatorTemplate> to <ItemTemplate> and it should work!
The SeparatorTemplate has no DataItem. The separator is in between two items, there are always n-1 separators, so if databinding did work it would always leave the last item unused.
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