心血来潮,发现网络上问起此问题的人较多,于是花了点时间写了这篇文章
网络上大多讲datagrid的鼠标悬停变色问题.而2005里面gridview已将datagrid控件所替代
方法如下:
新建页面,从工具栏中拖入一个gridview控件:
重点:(在设计样式的时候,一定不要设置RowStyle 里面BackColor属性值.(有点遗憾))如图:
将数据绑定代码写好以后.选中gridview控件,添加 DataBound 事件,放如以下代码:
protected void GridView1_DataBound(object sender, EventArgs e)
{
for (int i = 0; i <= this.GridView1.Rows.Count - 1; i++)
{
this.GridView1.Rows[i].Attributes.Add("onmouseover", "this.bgColor='orange'");
this.GridView1.Rows[i].Attributes.Add("onmouseout", "this.bgColor=''");
}
}
以上代码意思是鼠标悬停时对应的row背景变为桔黄色.鼠标移开还原.
最后效果如图:
以上为原创,有好方法请留言,谢谢!