前台脚本
<script type="text/javascript">
var prev=null;
function selectx(row) /**//*改变选中行的颜色还原为选中行的颜色*/
{
if(prev!=null)
{
prev.style.backgroundColor='#FFFFFF';
}
row.style.backgroundColor='#EEEEEE';
prev=row;
}
</script>
<asp:GridView ID="GridView1" runat="server" onrowdatabound="GridView1_RowDataBound">
</asp:GridView>
后台
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "if(this!=prev){c=this.style.backgroundColor;this.style.backgroundColor='#EEEEEE'}");//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseout", "if(this!=prev){this.style.backgroundColor=c}");//当鼠标移开时还原背景色
e.Row.Attributes["style"] = "Cursor:hand";//设置悬浮鼠标指针形状为"小手"
e.Row.Attributes.Add("onclick", "selectx(this)");//调用页面javascript
}
}