DataGrid:鼠標移動行變色、單擊行彈出提示窗體

此代碼實現了以下功能:

  1.當鼠標在DataGrid上移動時行變化背景色;

  2.單擊DataGrid行彈出提示窗體;

  3.當鼠標放在DataGrid上時鼠標樣式變爲"hand"樣式。

  在DataGrid控件的項綁定事件中寫入以下代碼:

  private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
   {
    e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Bisque'");
    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='White'");
    e.Item.Style["cursor"] = "hand";
    e.Item.Attributes.Add("onclick", "alert(/"This row's Product Name: " + e.Item.Cells[0].Text + "/");");
   }
  }
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章