鼠标移到或移开gridview上改变背景色

收藏本信息编号:290 发布时间:2009-08-07 截止日期:2010-12-07 地区:北京市.宣武区

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    int num = GridView1.PageIndex + 1;
    Label1.Text = "第" + num + "页/共" + GridView1.PageCount + "页";

    if (e.Row.RowIndex != -1)
    {
        int indexID = this.GridView1.PageIndex * this.GridView1.PageSize + e.Row.RowIndex + 1;
        e.Row.Cells[0].Text = indexID.ToString();
    }

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "if(this!=prevselitem){this.style.backgroundColor='#Efefef'}");//当鼠标停留时更改背景色
        e.Row.Attributes.Add("onmouseout", "if(this!=prevselitem){this.style.backgroundColor='#ffffff'}");//当鼠标移开时还原背景色
        e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");
    }
}

aspx
<script type="text/javascript">
var prevselitem=null;
function selectx(row)
{
   if(prevselitem!=null)
   {
      prevselitem.style.backgroundColor='#ffffff';
   }
   row.style.backgroundColor='PeachPuff';
   prevselitem=row;
}
</script>
 

发布人信息

[错误报告] [推荐] [收藏][打印] [关闭] [返回顶部]

当前共有0人发表了评论.

推荐信息

最新信息