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='';");  
              }  
           }  
        }
    }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM