GridView的几个事件(如实现: 行的双击/单击/捕捉键盘按键/鼠标悬浮/移出效果)

来源:互联网 发布:动画运动规律知乎 编辑:程序博客网 时间:2024/05/27 06:13

  1. [前台]
    1. <script language="javascript">        
    2.         function DbClickEvent(d)
    3.         {
    4.               window.alert("事件类型: DoubleClidk  作用对象: " + d);            
    5.         }
    6.         function ClickEvent(d)
    7.         {
    8.               window.alert("事件类型: onClick  作用对象: " + d);            
    9.         }
    10.         function GridViewItemKeyDownEvent(d)
    11.         {
    12.               window.alert("事件类型: GridViewItemKeyDownEvent  作用对象: " + d);       
    13.         }
    14.         function KeyDownEvent()
    15.         {
    16.                ifevent.altKey && event.keyCode > 48 && event.keyCode < 54 )            
    17.                {                
    18.                       window.alert("事件类型: FormKeyDownEvent  选中记录数: " + ( parseInt(event.keyCode) - 48 )); 
    19.                }                      
    20.         }           
    21. </script>
  2. [后台]
    1. if( e.Row.RowType == DataControlRowType.DataRow)
    2. {
    3.          //鼠标移动到每项时颜色交替效果
    4.          e.Row.Attributes.Add("onMouseOut""this.style.backgroundColor='White';this.style.color='#003399'");
    5.          e.Row.Attributes.Add("onMouseOver""this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");
    6.  
    7.          //单击/双击 事件
    8.          e.Row.Attributes.Add("OnDblClick""DbClickEvent('" + e.Row.Cells[1].Text + "')");
    9.          e.Row.Attributes.Add("onClick""ClickEvent('" + e.Row.Cells[1].Text + "')");
    10.  
    11.          e.Row.Attributes.Add("onKeyDown""GridViewItemKeyDownEvent('" + e.Row.Cells[1].Text + "')"); 
    12.  
    13.          //设置悬浮鼠标指针形状为"小手"
    14.          e.Row.Attributes["style"] = "Cursor:hand";
    15.          
    16. }
原创粉丝点击