A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 赵大宝 中级黑马   /  2012-10-31 18:44  /  1026 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

鼠标停留在GridView某一行时  行的颜色改变

protected void gvdegreetype_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='GhostWhite'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
        }
    }



---------------------------------------------



可以选择GRIDVIEW控件,然后双击RowDataBound事件

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//当鼠标移到的时候设置该行颜色为"", 并保存原来的背景颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699CC'");
//当鼠标移走时还原该行的背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

2 个回复

倒序浏览
谢谢分享,值得学习
回复 使用道具 举报
呵呵这个是用于美化的。它的这段代码我经常用
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马