I am attempting to print out a line which contains an image tag within my ListView controller’s Item Template. I have tried this multiple ways with no success.
<ItemTemplate>
<tr id="itemTemplate" runat="server">
<td>
<asp:Literal ID="litImg" runat="server" Text='<%= "<img src="" & PathtoImg & "ProcessImage.aspx?Img=" & Eval("Img") & "&PID="Resize"" alt=""ProductID"" />")))) %>' />
</td>
<td>
<asp:Literal ID="litID" runat="server" Text='<%# Eval("Department") %>' />
</td>
</tr>
</ItemTemplate>
The first eval does not work (and is a bit of a cluster) the second, simple line does.
It does not error, but it displays
and obviously this doesn’t work
<img src="<%= PathtoImg %>ProcessImage.aspx?Img=<%= Eval("Img")%>&PID=Resize" alt="ProductID" />
as it gives the error
“Databinding methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control. “
This is my first time using a Listview and I am very unfamiliar with these templates. Is what I want – displaying a data item with a server variable within the src of an image tag – possible?
Use a code-behind function or runat=”server” your HTML control:
Markup:
Code-behind:
Other option: