DataGrid和GridView鼠标移动上面背景变色
gridview鼠标移动背景变色,在rowdatabound事件中添加如下代码:
protected void gridview2_rowdatabound(object sender, gridviewroweventargs e)
{
if (e.row.rowtype == datacontrolrowtype.datarow)
{
e.row.attributes.add("onmouver", "javascript:c=this.style.backgroundcolor;this.style.background='#b0e0e6';");
e.row.attributes.add("onmouseout", "javascript:this.style.background=c;");
}
}
datagrid鼠标移动背景变色,在itemdatabound中添加如下代码
protected void datagrid1_itemdatabound(object sender, datagriditemeventargs e)
{
if (e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)
{
e.item.attributes["onmouseover"] = "javascript:c=this.style.backgroundcolor;this.style.background='#b0e0e6';"; //current 粉蓝色 //--#6699ff 蓝色 #ffff00 黄色 #ffffe0 亮黄色
e.item.attributes["onmouseout"] = "javascript:this.style.background=c;";
}
}
摘自 爱智旮旯