您的位置:首页 > 编程语言 > ASP

GridView显示数据特效——鼠标经过行背景高亮并呈手型

2015-11-06 14:39 387 查看
在用GridView控件显示数据时,它的默认的样式很丑,也没有鼠标经过行背景高亮和鼠标呈现手型的特效,今天实现了这个特效。

代码如下。

//鼠标经过行背景高亮并变手型

        protected void ClassGridView_RowDataBound(object sender, GridViewRowEventArgs e)

        {

             int i;

             //执行循环,保证每条数据都可以更新

             for (i = 0; i <= ClassGridView.Rows.Count; i++)

             {

                 //首先判断是否是数据行

                 if (e.Row.RowType == DataControlRowType.DataRow)

                 {

                     //当鼠标停留时更改背景色

                     e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='AliceBlue';this.style.cursor='pointer'");

                     //当鼠标移开时还原背景色

                     e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

                 }

             }

        }

如果只是想要行背景高亮或者添加其他特效只需要修改 e.Row.Attributes.Add中的内容即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息