首页>
ASP.NET教程>
ASP.NET2.0下为GridView添加鼠标滑过(onmouseover、onmouseout)的行颜色高亮效果!
ASP.NET2.0下为GridView添加鼠标滑过(onmouseover、onmouseout)的行颜色高亮效果!
时间:2009-06-30 17:02:38
作者:互联网
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//将满足特定条件的行标为高亮
if (e.***.RowType == Da***ontrolRowType.DataRow)//判定当前的行是否属于datarow类型的行
{
int money = Co***rt.ToInt32(Da***inder.Eval(e.***.DataItem, "MONEY"));//取当前行的列值
if (money == 77)
e.***.BackColor = Co***.Red;
//string customer = (string)Da***inder.Eval(e.***.DataItem, "CUSTOMER");
string customer = Da***inder.Eval(e.***.DataItem, "CUSTOMER").ToString();
if (customer == "sdf")
e.***.BackColor = Co***.Red;
}
//加入鼠标滑过的高亮效果
if (e.***.RowType == Da***ontrolRowType.DataRow)//判定当前的行是否属于datarow类型的行
{
//当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
e.***.Attributes.Add("onmouseover", "cu***ntcolor=this.style.backgroundColor;th***style.backgroundColor='yellow',th***style.fontWeight='';");
//当鼠标离开的时候 将背景颜色还原的以前的颜色
e.***.Attributes.Add("onmouseout", "th***style.backgroundColor=currentcolor,th***style.fontWeight='';");
}
//单击行改变行背景颜色
if (e.***.RowType == Da***ontrolRowType.DataRow)
{
e.***.Attributes.Add("onclick","th***style.backgroundColor='#99cc00'; th***style.color='buttontext';th***style.cursor='default';");
}