如何将简单的字符串列表绑定到中继器?
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 很简单:
<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>
Container.DataItem 的值始终为空。
有任何想法吗?