I am displaying images from my application to datalist.Source code is:
我正在将我的应用程序中的图像显示给datalist。源代码是:
<asp:DataList ID="dtlist" runat="server" RepeatColumns="4" CellPadding="5">
<ItemTemplate><asp:Image Width="100" ID="Image1" ImageUrl='<%# Bind("Name", "~/Images/{0}") %>' runat="server" />
<br /></ItemTemplate>
<ItemStyle BorderColor="Brown" BorderStyle="dotted" BorderWidth="3px" HorizontalAlign="Center"VerticalAlign="Bottom" />`
</asp:DataList>
code behind is
代码背后是
protected void BindDataList()
{
DirectoryInfo dir = new DirectoryInfo(MapPath("Images"));
FileInfo[] files = dir.GetFiles();
ArrayList listItems = new ArrayList();
foreach (FileInfo info in files)
{
listItems.Add(info);
}
dtlist.DataSource = listItems;
dtlist.DataBind();
}
protected void btnsave_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(fileupload1.PostedFile.FileName);
fileupload1.SaveAs(Server.MapPath("Images/" + filename));
BindDataList();
}
As this I want to display all the images from local drive to data list. ex from C:\Sales n purchases\ImagesFolder
to datalist.
因此,我想显示从本地驱动器到数据列表的所有图像。从C:\ Sales n购买\ ImagesFolder到datalist。
please any one help me. Thanks in advance.
请任何人帮助我。提前致谢。
1 个解决方案
#1
1
Please try with the below code snippet.
请尝试使用以下代码段。
<ItemTemplate>
<asp:Image Width="100" ID="Image1" ImageUrl='<%# String.Format("{1}\\{0}", Eval("Name"), Eval("Directory")) %>'
runat="server" />
<br />
<asp:Label id="lblImageSrc" runat="server" Text='<%# String.Format("{1}\\{0}", Eval("Name"), Eval("Directory")) %>'></asp:Label>
</ItemTemplate>
#1
1
Please try with the below code snippet.
请尝试使用以下代码段。
<ItemTemplate>
<asp:Image Width="100" ID="Image1" ImageUrl='<%# String.Format("{1}\\{0}", Eval("Name"), Eval("Directory")) %>'
runat="server" />
<br />
<asp:Label id="lblImageSrc" runat="server" Text='<%# String.Format("{1}\\{0}", Eval("Name"), Eval("Directory")) %>'></asp:Label>
</ItemTemplate>