2017-08-21 3 views
1

Wie erstellt man einen dynamischen src innerhalb einer foreach-Schleife?

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

Also, was ich versuche, für jedes Stück Kunst in einer Tabelle ein anderes Bild zu tun ist, angezeigt werden soll. Src = <% a.PicturePath%> scheint jedoch nicht den Trick zu machen (Ich habe es mit Zitaten probiert und es hat auch nicht funktioniert). Wie mache ich das?

+0

Bist du nicht ein Gleichheitszeichen fehlt Innerhalb? src = "<% = a.PicturePath%>" –

+0

Oh ja mein Original hatte das "=" – Xigaphactus

Antwort

1

Der asp:Image ist eine serverseitige Tag - Sie müssen hinter seiner ImageUrl Eigenschaft von Code einzustellen oder eine clientseitige <img> und legen Sie seine src Attribut:

<img src="<% =a.PicturePath %>" /> 
+0

Danke, es hat perfekt funktioniert – Xigaphactus

Verwandte Themen