Asp.net 2.0 GridView的幾個事件(如實現: 行的雙擊/單擊/捕捉鍵盤按鍵/滑鼠懸浮/移出效果))

來源:互聯網
上載者:User
(一).  樣本圖片

 

(二). 代碼

[前台]

<script language="javascript">        
        function DbClickEvent(d)
        {
              window.alert("事件類型: DoubleClidk  作用對象: " + d);            
        }
        function ClickEvent(d)
        {
              window.alert("事件類型: OnClick  作用對象: " + d);            
        }
        function GridViewItemKeyDownEvent(d)
        {
              window.alert("事件類型: GridViewItemKeyDownEvent  作用對象: " + d);       
        }
        function KeyDownEvent()
        {
               if( event.altKey && event.keyCode > 48 && event.keyCode < 54 )            
               {                
                      window.alert("事件類型: FormKeyDownEvent  選中記錄數: " + ( parseInt(event.keyCode) - 48 )); 
               }                      
        }           
</script>

[後台]

if( e.Row.RowType == DataControlRowType.DataRow)
{
         //滑鼠移動到每項時顏色交替效果
         e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
         e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");

         //單擊/雙擊 事件
         e.Row.Attributes.Add("OnDblClick", "DbClickEvent('" + e.Row.Cells[1].Text + "')");
         e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.Cells[1].Text + "')");

         e.Row.Attributes.Add("OnKeyDown", "GridViewItemKeyDownEvent('" + e.Row.Cells[1].Text + "')"); 

         //設定懸浮滑鼠指標形狀為"小手"
         e.Row.Attributes["style"] = "Cursor:hand";
         
}

  * 關於事件,不僅僅就這些, 還有更多, 用類似方法可以完成更複雜,效果更佳的頁面.

(三). 範例程式碼下載

        http://files.cnblogs.com/ChengKing/Gridview(DBclick%20OnmouseOver%20etc).rar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.