datatable加载

来源:互联网 发布:淘宝刷流量靠谱吗 编辑:程序博客网 时间:2024/05/23 16:55
 

 protected void Page_Load(object sender, EventArgs e)
        {
           
            string path1 = Request.PhysicalApplicationPath;
            string path = path1 + "\\upfile";
            DirectoryInfo dir = new DirectoryInfo(path);
            FileInfo[] finfo = dir.GetFiles();
            //Table tbllist = new Table();
            int cell = finfo.Length;
            int rows = 3;

            for (int i = 0; i < cell; i++)
            {
                TableRow tblrow = new TableRow();
                for (int j = 0; j < rows; j++)
                {
                    TableCell tblcell = new TableCell();
                    switch (j)
                    {
                        case 0:
                            tblcell.Text = i.ToString();
                            break;
                        case 1:
                            tblcell.Text = "<a href= upfile/" + finfo[i].ToString() + ">" + "下载" + "</a>";
                            break;
                        default:
                            tblcell.Text = finfo[i].ToString();
                            break;
                    }
                    tblrow.Cells.Add(tblcell);


                }

                Table1.Rows.Add(tblrow);

                //.Rows.Add(tblrow);
            }
            if (!IsPostBack)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("id", typeof(string));
                dt.Columns.Add("1id", typeof(string));
                dt.Columns.Add("2id", typeof(string));


                for (int i = 0; i < cell; i++)
                {
                    dt.Rows.Add(dt.NewRow());
                    string st = i.ToString();
                    dt.Rows[i][0] = i.ToString();

                    dt.Rows[i][1] = "<a href= upfile/" + finfo[i].ToString() + ">" + "下载" + "</a>";

                    dt.Rows[i][2] = finfo[i].ToString();
                }

                GridView1.DataSource = dt;
                GridView1.DataBind();
            }


        }

原创粉丝点击