设置鼠标滑过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';");
   }
}

转载于:https://www.cnblogs.com/zhaiajing1985/archive/2013/05/21/3091907.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值