您的位置:首页 > 其它

实现DataGrid的某一行随着鼠标的移入移出而改变颜色

2006-08-24 16:38 507 查看
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex!=-1) //鼠标在DataGrid中移动时,选中的那一行显示颜色
{
e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor);this.style.backgroundColor='#99cfff'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");

}
}

或者

在.aspx页面添加如下代码:
<script>
var curColor;
function MouseOver(Element)
{
curColor=Element.style.backgroundColor;
Element.style.backgroundColor="DarkGray";
Element.style.cursor="hand";
}
function MouseOut(Element)
{
Element.style.backgroundColor=curColor;
Element.style.cursor="default";
}
</script>

然后再.cs文件中添加如下代码:
在你的绑定DataGrid的代码中添加
foreach(DataGridItem CurRow in this.DataGrid1.Items)
{
CurRow.Attributes.Add("onmouseover","MouseOver(this);");
CurRow.Attributes.Add("onmouseout","MouseOut(this);");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐