![](https://www.cnblogs.com/Emoticons/xd/001.gif)
我觉得动态生成DataTable在有些需要测试返回Datatable数据集函数
和一些数据绑定控件测试其效果还是挺有用的~
贴码:(
Code
protected void Page_Load(object sender, EventArgs e)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
//生成DataTable 并添加10个
DataTable dt = new DataTable();
for (int i = 0; i < 10; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
dt.Columns.Add();
}
//往DataTable 里添加20行数据
for (int i = 0; i < 20; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
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)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
if (e.Row.RowType == DataControlRowType.DataRow)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//鼠标移动到每项时的颜色交替效果
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'");
}
}