List of bindings (from a string) to the repeater

How to associate a simple list of strings with 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 

HTML is simple:

  <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?

+7
source share
1 answer

Change <SeparatorTemplate> to <ItemTemplate> and it should work!

SeparatorTemplate does not have a DataItem. The separator is between two elements, there are always n-1 separators, so if the data binding really worked, it would always leave the last element unused.

+5
source

All Articles