1.拖一个gridview控件,添加RowCreated事件代码,如下:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onmouseover", "bgColor='LightCyan'");
e.Row.Attributes.Add("onmouseout", "bgColor=''");
}
2.以上代码变色时连header也随着一起变色,如果只希望datarow变色,加上一个判断即可.
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//判断是不是datarow,将header去掉
{
e.Row.Attributes.Add("onmouseover", "bgColor='LightCyan'");
e.Row.Attributes.Add("onmouseout", "bgColor=''");
}
}
本文介绍如何使用ASP.NET中的GridView控件实现数据行悬停时背景颜色变化的效果,并通过简单判断确保仅数据行而非表头参与变色。
527

被折叠的 条评论
为什么被折叠?



