//鼠标划过grdAutomobile的背景色
protected void grdAutomobile_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = -1; i < grdAutomobile.Rows.Count; i++)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#d1d7da'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
}
protected void grdAutomobile_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = -1; i < grdAutomobile.Rows.Count; i++)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#d1d7da'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
}
本文详细介绍了如何使用C#为GridView组件添加动态背景色效果,通过事件处理实现鼠标悬停和离开时的背景色变化,提升了用户的交互体验。此技巧适用于网页开发、桌面应用等场景。

5101

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



