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

来源:互联网 发布:linux如何安装vsftpd 编辑:程序博客网 时间:2024/05/14 04:29

在用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中的内容即可。

0 0
原创粉丝点击