I have the following List
:
private List<System.Web.UI.WebControls.Image> _searchResultList = new List<System.Web.UI.WebControls.Image>();
This List may contain several Images with different URLs.
I have the following Repeater
:
<asp:Panel ID="SearchPanel" runat="server" ScrollBars="Vertical">
<asp:Repeater ID="Repeater" runat="server">
<ItemTemplate>
<asp:Image height="32" width="32" runat="server"/>
</ItemTemplate>
</asp:Repeater>
</asp:Panel>
Using DataSource
to display the images doesn't seem to work.
Repeater.DataSource = _searchResultList;
Repeater.DataBind();
What am I doing wrong?
The
_searchResultList
is not a list of strings so you can't useImageURL='<%Container.DataItem.ToString()%>'
. Because_searchResultList
is a list of images you should bind theImageUrl
property. This should works fine for you:In this example
Container.DataItem
refers to anImage
control. This is why we usedEval("ImageUrl")
to get theImageUrl
property of eachImage
control.