Home > DeveloperSection > Forums > display [no image found] when image src returns no image
Brad Pitt
Brad Pitt

Total Post:61

Points:429
Posted on    January-16-2015 10:34 PM

 ASP.Net C#  HTML5  Image View 
Ratings:


 1 Reply(s)
 761  View(s)
Rate this:

I generate my image src from databse field called [pictureName]. I want when Picture name is null or the name doesn't return image to display [image not found] picture. 
Here is my aspx code to generate img:

<img src="WEBIMAGES/<%#Eval("BrandName")%>/<%# Eval("PictureName") %>" alt="" title="<%# Eval("ProductName") %>">

my images divided into folders for each brand. i have noImage.jpg in every folder. 
how to display this image when no image displayed. 
I'm using asp.net webforms 
I tried to use onerror event, but not working. 

Thanks in advance



Pawan Shukla
Pawan Shukla

Total Post:29

Points:203
Posted on    January-16-2015 11:01 PM

You could use a coalesce on the picture name as follows:

<img src="WEBIMAGES/<%#Eval("BrandName")%>/<%# Eval("PictureName") ?? 'noImage.jpg' %>" alt="" title="<%# Eval("ProductName") %>"> 


Don't want to miss updates? Please click the below button!

Follow MindStick