使用被存储为一个字符串的文件名设置的ImageUrl [英] Setting ImageUrl using a filename which is stored as a string
问题描述
我想使用的存储为一个字符串的文件名来设置的ImageUrl。我得到任何错误,但也只是在页面上的空图片框。任何帮助深表AP preciated。
I'm trying to set an ImageUrl using a filename which is stored as a string. I'm getting no errors but there's just an empty picture box on the page. Any help is much appreciated.
ASPX ..
<asp:Image ID="imgAvatar" width="80px" runat="server" />
VB ..
imgAvatar.ImageUrl = (DataBinder.Eval(e.Item.DataItem, "avatarfilename").ToString)
我知道,因为它输出到屏幕上我这样做时,文件名是正确存放。
I know the filename is stored correctly as it outputs to the screen when I do this..
Response.Write (DataBinder.Eval(e.Item.DataItem, "avatarfilename").ToString)
推荐答案
您正在输出文件〜/ [休息-的文件路径
这不是一个有效的路径。在〜
指根,但服务器来渲染的完整路径。
That's not a valid path. The "~"
means root, but the server has to render the full path.
您可以尝试像使用Server.Mappath(路径);
,但是你错过了第一个/
让你有错误的道路在你的数据库中。
You can try something like Server.MapPath(path);
but you're missing the first "/"
so you have the wrong path in your database.
这篇关于使用被存储为一个字符串的文件名设置的ImageUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!