首页 > 其他 > 详细

循环添加label并获取上传文件名字的扩展名和文件大小

时间:2014-02-19 16:57:47      阅读:381      评论:0      收藏:0      [点我收藏+]

前台代码

 

<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="添加label" />
    <asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Panel ID="Panel1" runat="server" ViewStateMode="Enabled"></asp:Panel>

 

后台

 

bubuko.com,布布扣
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["demo"] = new List<Label>();
            }
        }
bubuko.com,布布扣

 

 

bubuko.com,布布扣
            string file_KB = FileUpload1.PostedFile.ContentLength.ToString() + "KB<br>";//获取文件大小
            string file = FileUpload1.FileName;//获取上传文件名字




            List<Label> list = Session["demo"] as List<Label>;
            Label l = new Label();
            l.ID = "lbl" + (list.Count + 1);
            l.Text = file + file_KB;
            list.Add(l);
            Session["demo"] = list;
            foreach (Label item in list)
            {
                Panel1.Controls.Add(item);
            }
            int max = list.Count;
            List<string> lavlist = new List<string>();
            foreach (Label item in list)
            {
                lavlist.Add(item.Text);
            }
bubuko.com,布布扣

循环添加label并获取上传文件名字的扩展名和文件大小

原文:http://www.cnblogs.com/914556495wxkj/p/3555041.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!