现在的位置: 首页 > 综合 > 正文

gridview中实现鼠标悬停高亮显示

2012年10月08日 ⁄ 综合 ⁄ 共 713字 ⁄ 字号 评论关闭
在datagrid中的ItemDataBound事件中写如下代码:
private void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#66CCFF'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}

在girdview中的RowDataBound事件中写下如下代码:

 
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;");
}
}

抱歉!评论已关闭.