<asp:DataList ID="DataList2" runat="server" RepeatColumns="6"
RepeatDirection="Horizontal">
<ItemTemplate>
<br />
<a href='<%# "previewGoodWork.aspx?goodworkpicturepath="+DataBinder.Eval(Container.DataItem,"goodworkpicturepath") %>' OnCommand="ImageButton1_Command" ImageUrl='<%# Eval("goodworkpicturepath") %>' > <asp:Image ID="Image3" runat="server" ImageUrl='<%# Eval("goodworkpicturepath") %>' /></a>
<br />
</ItemTemplate>
</asp:DataList>
网页中:
<ItemTemplate>
<a href='' target="_blank" runat="server" id="vLnkImage">
<asp:Image id="vImage" runat="server"></asp:Image>
</a>
</ItemTemplate>
代码中:
if(e.Item.ItemIndex > -1)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
System.Web.UI.WebControls.Image Img = (System.Web.UI.WebControls.Image)e.Item.FindControl("vImage");
Img.ImageUrl = "/Images/+drv["c_FileName"].ToString();
HtmlAnchor Link1 = (HtmlAnchor)e.Item.FindControl("vLnkImage");
Link1.HRef = "http://"+drv["c_URL"].ToString();
}
Datalist调用本地文件绑定图片
<asp:DataList ID="dList1" runat="server" RepeatColumns="4">
<ItemTemplate>
<asp:Image runat="server" ID="img1" ImageUrl='<%# Eval("Name","~/Images/{0}") %>' Width="50px" Height="40px" name="imgA" />
<img src="images/aa.jpg" width="50px" height="40px" onclick="show()" name="imgB"/>
</ItemTemplate>
</asp:DataList>
后台
string path =MapPath("~/Images/");
DirectoryInfo dir = new DirectoryInfo(path);
dList1.DataSource = dir.GetFiles();
dList1.DataBind();