C# GridView 给某行或某列绑定点击事件和鼠标事件

 protected void GridViewEx1_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.DataRow)//判断单击行是否为数据行  
         {  
              DataRowView row = (DataRowView)e.Row.DataItem;  
              e.Row.ID = GridViewEx1.DataKeys[e.Row.RowIndex]["ID"].ToString();//ID为唯一能够标识一条记录的字段  
              if (e.Row.ID != null && row != null)  
              {  
                 e.Row.Cells[1].Attributes.Add("ondblclick", "window.open('ParhelionRestEdittPage.aspx?index=" + (e.Row.RowIndex + 1).ToString() + "&id=" + e.Row.Cells[0].Text.Trim() + "',null,'width=400,height=108,left=300,top=200');");

                 e.Row.Cells[1].Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F89E14',this.style.cursor='pointer';");  
                  //鼠标事件 this.style.backgroundColor='#F89E14' 列背景色  this.style.cursor='pointer' 鼠标放上去样式  
                 e.Row.Cells[1].Attributes.Add("onmouseout", "this.style.backgroundColor='';");  
              }  
           }  
        }
    }

  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值