直放站内的图像没有显示出来(Image inside repeater is not showing up)

编程入门 行业动态 更新时间:2024-10-25 22:25:50
直放站内的图像没有显示出来(Image inside repeater is not showing up)

我有一个中继器来显示照片。 它是这样填充的:

AcctRepeaterPhoto.DataSource = ""; dDateID = Convert.ToInt32(lDateID.InnerText); saqConnection.conn = MySQLConn; sqlDataAdapter adp = new SqlDataAdapter("Select * from MyTable", conn) DataSet ds = New Dataset(); adp.Fill(ds, "MyPhotoPage"); AcctRepeaterPhoto.DataSource = ds; AcctRepeaterPhoto.DataBind(); ds.Dispose; conn.Close;

我100%确定这是有效的,因为我使用几乎相同的代码来处理我的表单的其他3个部分,并且它们都完美地工作。

ASP方面,我不太确定...

其中大部分都是有道理的,但是应该显示图像的线没有任何显示:

<asp:Image runat="server" ImageUrl='<%# string.Format("D:/MyPics/Photos/{0}", Eval("PhotoLink")) %>' />

当我查看生成的页面的源代码时,它解决了

<img src="D:/MyPics/Photos/MyImageName.jpg">

但它只是显示无效图像显示的空白方块。

如果我将它切换到:

<asp:Image runat="server" ImageUrl='<%# string.Format("D:\\MyPics\\Photos\\{0}", Eval("PhotoLink")) %>' />

它仍然只显示空的方块,但这次页面的来源显示

<img src="D:\MyPics\Photos\MyImageName.jpg">

我检查了路径,并在“D:\ MyPics \ Photos \”中有一个名为“MyImageName.jpg”的文件。

任何人都知道发生了什么事? 为什么这张图片不显示?

I've got a repeater to display photos. It's filled like so:

AcctRepeaterPhoto.DataSource = ""; dDateID = Convert.ToInt32(lDateID.InnerText); saqConnection.conn = MySQLConn; sqlDataAdapter adp = new SqlDataAdapter("Select * from MyTable", conn) DataSet ds = New Dataset(); adp.Fill(ds, "MyPhotoPage"); AcctRepeaterPhoto.DataSource = ds; AcctRepeaterPhoto.DataBind(); ds.Dispose; conn.Close;

I'm 100% sure this works, because I use nearly identical code for 3 other parts of my form and they all work perfectly.

The ASP side, I'm not so sure about...

Most of it makes sense, but the line that's supposed to display the image is displaying nothing:

<asp:Image runat="server" ImageUrl='<%# string.Format("D:/MyPics/Photos/{0}", Eval("PhotoLink")) %>' />

When I look at the source code of the generated page, it's resolving to

<img src="D:/MyPics/Photos/MyImageName.jpg">

But it's just showing that empty square that invalid images show as.

If I switch it to:

<asp:Image runat="server" ImageUrl='<%# string.Format("D:\\MyPics\\Photos\\{0}", Eval("PhotoLink")) %>' />

it still only shows that empty square, but this time the source of the page shows

<img src="D:\MyPics\Photos\MyImageName.jpg">

I've checked the path, and there is a file in "D:\MyPics\Photos\" called "MyImageName.jpg".

Anyone know what's going on? Why won't this image show?

最满意答案

您需要使用URL而不是文件路径, ImageUrl属性需要一个URL

使用ImageUrl属性指定要在图像控件中显示的图像的URL。 您可以使用相对或绝对网址。 相对URL将图像的位置与Web页面的位置相关联,而无需在服务器上指定完整路径。 该路径相对于网页的位置。 这样可以更轻松地将整个站点移动到服务器上的另一个目录,而无需更新代码。 绝对URL提供完整路径,因此将网站移动到其他目录需要您更新代码。

您也可以将您的物理路径传递给Server.MapPath ,如果您有权限访问此映像文件夹,它将返回映像的正确网址

类似的东西:

<asp:Image runat="server" ImageUrl='<%# Server.MapPath(string.Format("D:/MyPics/Photos/{0}", Eval("PhotoLink"))) %>' />

You need to use a URL to your image not the file path, ImageUrl property takes a URL

Use the ImageUrl property to specify the URL of an image to display in the Image control. You can use a relative or an absolute URL. A relative URL relates the location of the image to the location of the Web page without specifying a complete path on the server. The path is relative to the location of the Web page. This makes it easier to move the entire site to another directory on the server without updating the code. An absolute URL provides the complete path, so moving the site to another directory requires that you update the code.

You can also just pass your physical path to Server.MapPath which will return the correct url of the image if you have permission to this image folder

Something like that:

<asp:Image runat="server" ImageUrl='<%# Server.MapPath(string.Format("D:/MyPics/Photos/{0}", Eval("PhotoLink"))) %>' />

更多推荐

本文发布于:2023-07-19 02:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1171535.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   直放站   Image   repeater   showing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!