Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i use datalist to show records . My problem is , when imageurl is null it shows nothing on the page. How can i load default.jpg picture ? binding is done on run time ( using DataEval.DataBinder)

Here is my code:

HTML
<img id="client" border="0" alt="" height="90px" src='Admin/client_image/<%# DataBinder.Eval(Container, "DataItem.client_img_path")%>'width="80px">
Posted
Updated 28-Sep-11 18:45pm
v3

Why not try altering your SQL Statement to use this
syntax:
SQL
SELECT id, name, ISNULL(pictureurl, 'Default.jpg') as PictureURL
FROM Users


This will replace any null values in field "pictureurl" with "default.jpg"
or

try this:

<img>
src='<%#iif(container.dataitem("image")="","images/no_img.gif",container.dat
aitem("image")) %>'></img>


hope this helps,
 
Share this answer
 
You can modify your code a bit :
HTML
<img id="client" border="0" alt="" height="90px" src="Admin/client_image/<%# (DataBinder.Eval(Container, "DataItem.client_img_path") == null) ? " default.jpg=" : DataBinder.Eval(Container, "DataItem.client_img_path" %>" width="80px"></img>


What I have done here is, before assigning any value to src we first evaluate the DataBinder.Eval(Container, "DataItem.client_img_path"). If it is null then assign Default.jpg else assign the value of DataBinder.Eval(Container, "DataItem.client_img_path").

Hope this helps.
All the best.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900