gpt4 book ai didi

c# - 图像不显示与 asp.net 转发器

转载 作者:太空宇宙 更新时间:2023-11-03 23:07:35 29 4
gpt4 key购买 nike

我想用中继器显示文件夹图像中的图片,但我不知道为什么无法显示问题图片。

 <div data-u="slides" style="cursor: default; position: relative; top: 0px; left: 0px; width: 800px; height: 356px; overflow: hidden;">

<asp:Repeater runat="server" ID="RepaterImages">
<ItemTemplate>
<div runat="server" data-p="144.50">

<img id="Image" runat="server" data-u="image" style="Width:120px;" src='<%#Container.DataItem %>'/>

</div>
</ItemTemplate>
</asp:Repeater>
</div>

protected void Page_Load(object sender, EventArgs e)
{
int id = Convert.ToInt32(Request.QueryString["id"]);

var path = Server.MapPath("ProjectsImages/ ");

var images = Directory.GetFiles(path,id+"*");

ArrayList list = new ArrayList();

foreach (var img in images)
{

list.Add(img);

}
RepaterImages.DataSource = images;
RepaterImages.DataBind();
}

最佳答案

您的代码存在问题,您使用的是图像的物理路径。您将必须提供中继器的相对路径。如下更改您的代码,我认为它应该可以工作:

protected void Page_Load(object sender, EventArgs e)
{
try
{
int id = Convert.ToInt32(Request.QueryString["id"]);
string relativePath = "/ProjectsImages/";
var path = Server.MapPath(relativePath);
var images = Directory.GetFiles(path, id + "*").Select(x =>
{
var arrPath = x.Split('\\');
string imgName = arrPath[arrPath.Length - 1];
return relativePath + imgName;
});
RepaterImages.DataSource = images;
RepaterImages.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}

关于c# - 图像不显示与 asp.net 转发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40654469/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com