- using System;
- using System.Collections.Generic;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- namespace WebApplication42
- {
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- DataTable dt=InitTable();
- DataTable nDt = dt.Clone();//克隆table
- DataRow[] drs=dt.Select("studentID like '%2%'");//获取符合条件的dr
- foreach (DataRow dr in drs)//将符合条件的dr添加到新的table里
- {
- nDt.ImportRow(dr);
- }
- }
- }
- /// <summary>
- /// 实例化table
- /// </summary>
- /// <returns></returns>
- private DataTable InitTable()
- {
- DataTable dt = new DataTable();
- dt.Columns.Add(new DataColumn("studentID"));
- dt.Columns.Add(new DataColumn("studentName"));
- for (int i = 0, j = 1000000; i < j; i++)
- {
- DataRow dr = dt.NewRow();
- dr["studentID"] = (i + 1);
- dr["studentName"] = "张" + (i + 1);
- dt.Rows.Add(dr);
- }
- return dt;
- }
- }
- }
http://blog.csdn.net/chadcao/article/details/7877955