日期:2014-05-17 浏览次数:20570 次
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" Width="100%"
BorderColor="#FF3300" Font-Size="Larger" >
<ItemTemplate>
<asp:image ID="Image1" runat="server" width="180" ImageUrl='<%#"cpimage/" +Eval("Name")%>' ToolTip='<%#Eval("Name").ToString().Replace(".jpg","")%>' />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Name").ToString().Replace(".jpg","")%>' ForeColor="Fuchsia" BackColor="#FF9900" Font-Size="Larger" CssClass="mid" BorderColor="Aqua" BorderStyle="Double"></asp:Label>
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:ListBox ID="ListBox1" runat="server" Height="300px" Width="200px">
</asp:ListBox>
DirectoryInfo imagesfile = new DirectoryInfo(Server.MapPath("./cpimage"));
DataList1.DataSource = imagesfile.GetFiles("*.jpg");
DataList1.DataBind();
<ItemTemplate>
//这里加上单击事件
<asp:image ID="Image1" runat="server" width="180" ImageUrl='<%#"cpimage/" +Eval("Name")% OnClick='Image_Click'>' ToolTip='<%#Eval("ToolTip").ToString().Replace(".jpg","")%>' />
//cs处理代码中添加
protected void Image_Click(object o,EventArgs e)
{
System.Web.UI.Image image=null;
if(o is System.Web.UI.Image)