分割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);
}
}