【发布时间】:2013-08-19 17:22:10
【问题描述】:
我想在我的 asp.net 网页上显示图像列表。 图片位于文件夹中。 我的aspx代码是这样的
<asp:ListView runat="server" ID="lvPicturePaths">
<ItemTemplate>
<img src="<%# Container.DataItem %>" />
</ItemTemplate>
</ListView>
在我后面的代码中:
private void GetImagePaths()
{
List<string> pathForPictures=new List<string>();
var path=Server.MapPath("~/images/");
foreach(var PP in Directory.GetFiles(path))
{
pathForPictures.Add(PP);
}
lvPicturePaths.DataSource=pathForPictures;
lvPicturePath.DataBind();
}
问题是img标签的src属性需要相对路径,比如localhost/images...
现在我得到类似: C:\Inetpub\wwwroot\images\image1.jpg
【问题讨论】: