1.datagrid的行对鼠标的移动和点击变色的响应事件.
前台
<
script language
=
"
javascript
"
>
function aa(e)
{
for ( var i = 1 ;i < DataGrid1.rows.length; i ++ )
{
if (DataGrid1.rows[i].style.backgroundColor == " #f6ab00 " )
{
DataGrid1.rows[i].style.backgroundColor = "" ;
}
}
if (e.style.backgroundColor != " #f6ab00 " )
{
e.style.backgroundColor = " #f6ab00 " ;
}
}
</ script >
function aa(e)
{
for ( var i = 1 ;i < DataGrid1.rows.length; i ++ )
{
if (DataGrid1.rows[i].style.backgroundColor == " #f6ab00 " )
{
DataGrid1.rows[i].style.backgroundColor = "" ;
}
}
if (e.style.backgroundColor != " #f6ab00 " )
{
e.style.backgroundColor = " #f6ab00 " ;
}
}
</ script >
后台
private
void
DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Header)
{
e.Item.Attributes.Add( " onmouseover " , " if(this.style.backgroundColor != '#f6ab00') this.style.backgroundColor='#f6f6f6' " );
e.Item.Attributes.Add( " onmouseout " , " if(this.style.backgroundColor != '#f6ab00') this.style.backgroundColor='' " );
e.Item.Attributes.Add( " onclick " , " aa(this) " );
}
}
颜色可以根据页面风格进行修改
{
if (e.Item.ItemType != ListItemType.Header)
{
e.Item.Attributes.Add( " onmouseover " , " if(this.style.backgroundColor != '#f6ab00') this.style.backgroundColor='#f6f6f6' " );
e.Item.Attributes.Add( " onmouseout " , " if(this.style.backgroundColor != '#f6ab00') this.style.backgroundColor='' " );
e.Item.Attributes.Add( " onclick " , " aa(this) " );
}
}