datatable加载

 

 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();
            }


        }

阅读更多
文章标签: string path table object
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭