开发者

ASP.NET Datalist image not displaying

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();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜