前台代码
<div> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="添加" /> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Panel ID="Panel1" runat="server" ViewStateMode="Enabled"></asp:Panel> <asp:HiddenField ID="HiddenField1" runat="server" /> <br /> 个数<br /> <asp:Label ID="Label3" runat="server"></asp:Label> <br /> <p id="p1" runat="server"><%=f%></p> <br /> <br /> <br /> <br /> <br /> <br /> <br />获取的数值只要是传给label都可以正常显示<br /> <asp:Label ID="Label2" runat="server"></asp:Label> </div>
后台
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Session["demo"] = new List<String>(); } } public static string f; protected void Button2_Click(object sender, EventArgs e) { string file_KB = FileUpload1.PostedFile.ContentLength.ToString() + "KB<br>";//获取文件大小 string file = FileUpload1.FileName;//获取上传文件名字 string URL = "http://amid01110/456/" + file + " "; List<string> list = Session["demo"] as List<string>; Session["demo"] = list; string lntext = "<a href='" + URL + "' >" + file + "</a>" + "大小" + file_KB + "上传文件成功"; list.Add(lntext); foreach (string item in list) { f = item; //p1.InnerHtml = item; Response.Write(item); string a = item; string b = Session["demo"].ToString(); } int max = list.Count; Label2.Text = max.ToString(); Label3.Text = list.Count.ToString(); }