分割DataTable

作者:互联网   出处:控件中国网   2014-11-05 19:05:28   阅读:1

分割DataTable

//分割DataTable
        private IList<DataTable> ListData()
        {
            //按DIVIDER分割
            List<DataTable> dtList = new List<DataTable>();
            const int DIVIDER = 5;
            DataTable dtData = (DataTable)this.Session["Table"];
            for (int i = 0; i < Math.Ceiling(dtData.Columns.Count / (double)DIVIDER); i++)
            {
                DataTable subdt = new DataTable();
                dtData.Columns.Cast<DataColumn>().Skip(DIVIDER * i).Take(DIVIDER).Select(cl => cl.ColumnName).ToList().ForEach(name => subdt.Columns.Add(name));
                dtList.Add(subdt);
            }
            foreach (DataRow row in dtData.Rows)
                dtList.ForEach(dt => dt.ImportRow(row));
            return dtList;
        }

        private void DisplayGrid()
        {
            IList<DataTable> listdt = ListData();
            foreach (DataTable dt in listdt)
            {
                GridView gv = new GridView();
                gv.DataSource = dt;
                gv.DataBind();
                PlaceHolder1.Controls.Add(gv);
            }
        }

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat