如何在运行时显示默认图像? [英] How to Display Default image on the run time?

查看:90
本文介绍了如何在运行时显示默认图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用数据列表显示记录.我的问题是,当imageurl为null时,它在页面上什么也不显示.如何加载default.jpg图片?绑定是在运行时完成的(使用DataEval.DataBinder)

这是我的代码:

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:

<img id="client" border="0" alt="" height="90px" src='Admin/client_image/<%# DataBinder.Eval(Container, "DataItem.client_img_path")%>'width="80px">

推荐答案

为什么不尝试更改您的SQL语句以使用此
语法:
Why not try altering your SQL Statement to use this
syntax:
SELECT id, name, ISNULL(pictureurl, 'Default.jpg') as PictureURL
FROM Users



这会将"pictureurl"字段中的所有空值替换为"default.jpg"


试试这个:



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,


您可以稍微修改一下代码:
You can modify your code a bit :
<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>



我在这里所做的是,在为src分配任何值之前,我们首先评估DataBinder.Eval(Container, "DataItem.client_img_path").如果为null,则分配Default.jpg,否则分配DataBinder.Eval(Container, "DataItem.client_img_path")的值.

希望这会有所帮助.
一切顺利.



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.


这篇关于如何在运行时显示默认图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆