更改Gridview颜色,然后更改鼠标并退出鼠标,原来的颜色又回来了 [英] Change Gridview Color on mouse change and on mouse out original color comes back
本文介绍了更改Gridview颜色,然后更改鼠标并退出鼠标,原来的颜色又回来了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用皮肤使用gridview,它具有不同的替代颜色.
我想在鼠标悬停时更改颜色,并在onmouseout上恢复为原始颜色.
I''m working with gridview using skin and it has different alternate color .
I want to change the color on mouseover and return to original color on onmouseout.
How should I do it?
推荐答案
您可以在GridView OnRowCreated事件上添加代码,例如:
You can add code on GridView OnRowCreated Event like :
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Alternate)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=MouseOvercolor;");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=MouseOutColor;");
}
else
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=MouseOverColor;");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=MouseOutColor;");
}
}
步骤1:以.aspx格式创建脚本
函数MouseOver()
{
document.getElementById(''gvComputeTax'').style.backgroundColor =蓝色";
}
函数MouseOut()
{
document.getElementById(''gvComputeTax'').style.backgroundColor =黑色";
}
第2步:在网格视图中调用该函数,如-
< asp:gridview id ="gvComputeTax" runat ="server" autogeneratecolumns ="False" gridlines ="None"
=" backcolor ="White" bordercolor ="White" borderstyle ="Ridge" borderwidth ="1px" cellspacing ="1" onmouseover ="MouseOver();" onmouseout ="MouseOut();">
Mahesh Patel
vipsha16@yahoo.com
step 1: create a script in .aspx form
function MouseOver()
{
document.getElementById(''gvComputeTax'').style.backgroundColor = "Blue";
}
function MouseOut()
{
document.getElementById(''gvComputeTax'').style.backgroundColor = "Black";
}
step 2: call the function in grid view like-
<asp:gridview id="gvComputeTax" runat="server" autogeneratecolumns="False" gridlines="None"
="" backcolor="White" bordercolor="White" borderstyle="Ridge" borderwidth="1px" cellspacing="1" onmouseover="MouseOver();" onmouseout="MouseOut();">
Mahesh Patel
vipsha16@yahoo.com
这篇关于更改Gridview颜色,然后更改鼠标并退出鼠标,原来的颜色又回来了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文