代码如下:
<%@ Page Language="C#" %><%@ Import Namespace="System.IO" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
protected void btnAdd_Click(object sender, EventArgs e) { if (upImage.HasFile) { if (CheckFileType(upImage.FileName)) { String filePath = "~/UploadImages/" + upImage.FileName; upImage.SaveAs(MapPath(filePath)); } } }
bool CheckFileType(string fileName) { string ext = Path.GetExtension(fileName); switch (ext.ToLower()) { case ".gif": return true; case ".png": return true; case ".jpg": return true; case ".jpeg": return true; default: return false; } }
void Page_PreRender() { string upFolder = MapPath("~/UploadImages/"); DirectoryInfo dir = new DirectoryInfo(upFolder); dlstImages.DataSource = dir.GetFiles(); dlstImages.DataBind(); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>FileUpload File</title></head><body> <form runat="server"> <div>
<asp:Label Text="Image File:" AssociatedControl Runat="server" />
<asp:FileUpload Runat="server" />
<br /><br /> <asp:Button Text="Add Image" OnClick="btnAdd_Click" Runat="server" />
<hr /> <asp:DataList RepeatColumns="3" runat="server"> <ItemTemplate> <asp:Image ImageUrl='<%# Eval("Name", "~/UploadImages/{0}") %>' Runat="server" /> <br /> <%# Eval("Name") %> </ItemTemplate> </asp:DataList> </div> </form></body></html>
请问1.ImageUrl='<%# Eval("Name", "~/UploadImages/{0}") %>'这句话是什么意思?
2.<%# Eval("Name") %> 这样怎么就会把文件名输出来了呢?
- 4 回答
- 0 关注
- 336 浏览
添加回答
举报
0/150
提交
取消