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 + "/");");
}
}