zoukankan      html  css  js  c++  java
  • 设置鼠标滑过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';");
       }
    }

  • 相关阅读:
    查找整数
    Ling To Xml 学习之 对xml增、删、改、查
    JS获得鼠标
    xml之数据岛绑定到表格
    C# 三种序列化[转]
    编程字体
    Oracle 、C#
    提示信息Javascript
    几个好用的日历控件
    收藏网站
  • 原文地址:https://www.cnblogs.com/zhaiajing1985/p/3091907.html
Copyright © 2011-2022 走看看