核心代码:
private void grdCustomer_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item )
{
e.Item.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
for (int i = 0; i< grdCustomer.Columns.Count; i++ )
{
e.Item.Cells[i].Attributes.Add("onmouseover",
"this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#99ccff'");
e.Item.Cells[i].Attributes.Add(
"onmouseout", "this.style.backgroundColor=this.oldcolor");
}
}
}
博客给出了一段核心代码,用于处理DataGrid控件的鼠标悬停样式。当鼠标悬停在DataGrid的项或交替项上时,会改变背景颜色,且鼠标离开后恢复原颜色,同时对单元格也做了相同的鼠标悬停样式处理。
41

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



