I want to display image in img control.
Asp code:
<asp:Image id="id" src='<%# Eval("Item.SmallPicPath") %>' Runat="Server" >
C# code:
public void Page_Load(Object sender, EventArgs e)
{
Glasses item=GetItemByID(GlassesID) //retrive record from data base
}
Glasses is a class that have property SmallPicPath.
I try to display image but i get error any idea how to fix it?
Thank you in advance!
The approach you’re trying to use is based on databinding, which generally isn’t good for a single image.
Instead, try something like this markup:
Then, in your code behind:
If you still want to use databinding for some reason, something like this should work (although there’s a performance cost compared to the other approach):
Code-behind:
Databinding is an optional operation; you need to call
DataBind()on the control (or its parent) to make it happen.You only need “Eval()” in cases that involve a data container (usually via a
DataSource) — which this one doesn’t.