pass the imagename to ImageUrl

Posted by Venkat | Labels: ,

Hi generally we are binding image to datalist..

so suppose if we store the image in the project folder

we have to get the name of the file and pass it on the src attribute of

img tag.. Ex:

<img src='< %#"BigImages/" & Eval("imagename") % > ' width ="485px" height="613px"  border="0" />
here bigimages is the foldername and imagename that we will get it from database..

so it will run properly..

Suppose if we do some task ie: hiding images - for that we have to

write the code in Datalist_ItemDatabound and also same for Gridview.. event has

been changed ie:ItemCommand..

At that if we use runat="server" id="Image1" for the above tag , while we get the

image through code it shows error

Unable to cast the html image to webcontrol image

for that use asp:image this is way you have to apply imageurl so it display the

image as per imagename - from the folder

<asp:Image ID="ProductImg"
CssClass="ProductImg"
runat="server"
ImageUrl=' < %# Eval("BigImages","imagename/{0}").Trim() % >'
AlternateText=' < %# Eval("imagename","").Trim() % >' 


PayOffers.in