I am using a Datalist to display images in a folder. The code is below:
<div>
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<img src = "<%# Container.DataItem %>" />
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>
</div>
code behind:
protected void Page_Load(object sender, EventArgs e)
{
string[] list = Directory.GetFiles(Server.MapPath("sony"));
List<string> aList = new List<string>开发者_StackOverflow;();
foreach (var rec in list)
{
aList.Add( rec);
}
DataList1.DataSource = aList;
DataList1.DataBind();
}
Its not displaying the images. please help
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] list = Directory.GetFiles(Server.MapPath("sony"));
var aList = from fileName in Directory.GetFiles(Server.MapPath("sony"))
select string.Format("/sony/{0}", Path.GetFileName(fileName));
DataList1.DataSource = aList;
DataList1.DataBind();
}
}
精彩评论