bsp; BindGridView();
}
}
private void BindGridView()
{
DataTable myData = CreateDataTable();
Session["MyData"] = myData;
gvPersonList.DataSource = myData;
gvPersonList.DataBind();
}
//手动生成DataTable
private DataTable CreateDataTable()
{
DataTable data = new DataTable();
DataColumn dcId = new DataColumn("ID", typeof(Int32));
//设置ID列自动递增
dcId.AutoIncrement = true;
//设置ID列初始值为1
dcId.AutoIncrementSeed = 1;
//设置ID列递增步长为1
dcId.AutoIncrementStep = 1;
//将ID列添加到DataTable中
data.Columns.Add(dcId);
data.Columns.Add(new DataColumn("Name", typeof(string)));
data.Columns.Add(new DataColumn("Age", typeof(int)));
data.Columns.Add(new DataColumn("Sex", typeof(bool)));
data.Columns.Add(new DataColumn("Married", typeof(bool)));
DataRow dataRow = null;
Random random = new Random();
//随机生成20条记录
for (int i = 0; i < 20; i++)
{
dataRow = data.NewRow();
//随机生成姓名
dataRow["Name"] = firstName.Substring(random.Next(firstName.Length), 1) + lastName.Substring(random.Next(lastName.Length), 1);
&n