repeater显示图片

来源:百度知道 编辑:UC知道 时间:2024/05/23 14:47:42
图片是以相对路径存在数据库的
<a href="Works/ShowPictures.aspx?id=<%#DataBinder.Eval(Container.DataItem, "p_id")%>" target="_blank">
<img alt="" width="150px" height="120px" src="Server.MapPath(<%#DataBinder.Eval(Container.DataItem, "path")%>)" />

用服务器控件image不行的,估计是id不能自动递增。

因为我的数据库相对路径是"~/pictures/photo/1.jpg"格式,img的src虽然也可以是相对路径,但是呢,经过测试,带了”~/“就不得行,所以想取服务器绝对路径,但是上面的代码也不得行。

<img alt="" width="150px" height="120px" src="<%#DataBinder.Eval(Container.DataItem, "path").ToString().Replace("~/","")%>" />
首先把~/去掉 如果图片是上层目录则 src="../<%#DataBinder.Eval(Container.DataItem, "path").ToString().Replace("~/","")%>" .如果是当前目录什么都不用写