• 设置鼠标滑过GridView行时变色


    设置鼠标滑过GridView行时变色

    //这里我们将对NorthWind数据库的Category表进行操作
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       //将CategoryID为偶数的行设为银色(Silver)
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
            //判定当前的行是否为数据行(即类型是否为DataRow)
            int cid = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "CategoryID"));
            //获取当前行的CategoryID列的值
            if (cid % 2 == 00)
                e.Row.BackColor = Color.Silver;
       }

      //设置鼠标滑过,行变色的效果
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
            //当鼠标放上去的时候 先保存当前行的背景颜色 并设置新的背景色
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow'; this.style.fontWeight='bold';");
            //当鼠标离开的时候 将背景颜色恢复成之前的颜色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor; this.style.fontWeight='';");
       }

       //设置鼠标点击,行变色、鼠标指针变成手状的效果
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
            e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#99cc00'; this.style.cursor='hand';");
       }
    }

  • 相关阅读:
    新年新气象,用新年的喜庆来迎接的生活
    vs2005中如何发布网站及打包web项目生成安装文件
    完整打印页面控件的解决方案
    vi使用体会
    向ATL DLL中传递C++对象
    CentOS 5.3配置软件源以及CVS服务器
    堆上多维数组的内存管理
    物理坐标与逻辑坐标
    好友列表的实现
    在STL中处理对象指针
  • 原文地址:https://www.cnblogs.com/zhaiajing1985/p/3091907.html
Copyright © 2020-2023  润新知