MasterOfDisaster MasterOfDisaster - 6 months ago 55
ASP.NET (C#) Question

How to create a dynamic src within a foreach loop?

<%foreach (Art a in SearchedArt)%>
<%{ %>
<td><asp:Image ID="Image1" runat="server" src=<%a.PicturePath %>/></td>
<td><%= Global.Users.Find(m => m.UserID == a.UserID).Name %></td>
<%foreach (string tag in a.Tags) %>
<%{ %>
<li><%= tag %></li>
<%} %>
<%} %>

So what I am trying to do is display a different image for each piece of art in a table. However, src=<%a.PicturePath%> doesn't seem to be doing the trick (I tried it with quotations and it didn't work either). How do I do this?

Answer Source

The asp:Image is a server-side tag - you need to set its ImageUrl property from code behind or use a client-side <img> and set its src attribute:

<img src="<% =a.PicturePath %>" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download