[英]I make fileUpload to save images in folder now i want to display it
那是從文件夾獲取圖像URL的代碼
<asp:Repeater ID="rptImages" runat="server">
<ItemTemplate>
<li>
<img alt="" style='height: 75px; width: 75px' src='<%# Eval("Images") %>' />
</li>
</ItemTemplate>
</asp:Repeater>
這確實顯示圖像
string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/Images"));
List<String> images = new List<string>(filesindirectory.Count());
foreach (string item in filesindirectory)
{
images.Add(String.Format("~/Images/{0}", System.IO.Path.GetFileName(item)));
}
rptImages.DataSource = images;
rptImages.DataBind();
當我運行它時,它說:“在為該請求提供服務的資源的編譯期間發生錯誤。請查看以下特定的錯誤詳細信息,並適當地修改您的源代碼。”
並以紅色顯示:( List<String> images = new List<string>(filesindirectory.Count());
)以紅色顯示
我該怎么辦?
我沒有遇到您提到的錯誤,但是在綁定上發現了另一個錯誤。
在這里,您應該使用Container.DataItem
更改綁定,並且由於您將~
用作路徑,因此應添加runat =“ server”,如本鏈接中所述 。
<img alt="" style='height: 75px; width: 75px' src='<%# Container.DataItem %>' runat="server"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.