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