Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind List(Of String) to Repeater [closed]

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?

like image 230
George Filippakos Avatar asked Jul 25 '12 14:07

George Filippakos


1 Answers

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.

like image 136
Willem Avatar answered Oct 09 '22 21:10

Willem