此代码实现了以下功能:
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 + "/");");
}
}
本文介绍了一种通过简单代码实现DataGrid交互效果的方法,包括改变行背景色、更改鼠标样式及弹出行信息提示窗体等功能。
3429

被折叠的 条评论
为什么被折叠?



