bsp; //随即生成介于20至100之间的年龄
int age = random.Next(20, 100);
dataRow["Age"] = age;
//随即设置性别
bool sex = (random.Next(100) % 2 == 0) ? true : false;
dataRow["Sex"] = sex;
if (((sex == true) && (age >= 22)) || ((sex == false) && (age >= 20)))//男性结婚年龄大于22周岁,女性结婚年龄大于20周岁
{
dataRow["Married"] = (random.Next(500) % 2 == 0) ? true : false;
}
else
{
dataRow["Married"] = false;
}
data.Rows.Add(dataRow);
}
return data;
}
//override掉这个方法
public override void VerifyRenderingInServerForm(Control control)
{
//注释掉下面的代码,否则在asp.net2.0下会报错(注:GridView是asp.net 2.0下的控件,1.1下一些控件也可以导出成Excel或者Word)
//base.VerifyRenderingInServerForm(control);
}
protected void btnToExcel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.BufferOutput = true;
//设定输出的字符集
Response.Charset = "GB2312";
//假定导出的文件名为FileName.xls
Response.AppendHeader("Content-Disposition