我觉得动态生成DataTable在有些需要测试返回Datatable数据集函数
和一些数据绑定控件测试其效果还是挺有用的~
贴码:(
Code
protected void Page_Load(object sender, EventArgs e)
{
//生成DataTable 并添加10个
DataTable dt = new DataTable();
for (int i = 0; i < 10; i++)
{
dt.Columns.Add();
}
//往DataTable 里添加20行数据
for (int i = 0; i < 20; i++)
{
dt.Rows.Add(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
//将 DataTable 绑到GridView中
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标移动到每项时的颜色交替效果
e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#ff0000'");
}
}
protected void Page_Load(object sender, EventArgs e)
{
//生成DataTable 并添加10个
DataTable dt = new DataTable();
for (int i = 0; i < 10; i++)
{
dt.Columns.Add();
}
//往DataTable 里添加20行数据
for (int i = 0; i < 20; i++)
{
dt.Rows.Add(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
//将 DataTable 绑到GridView中
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标移动到每项时的颜色交替效果
e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#ff0000'");
}
}