protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int i;
        for (i = 0; i < GridView1.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
           {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='Aqua'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
        }
    }
以上是我改变GridView颜色的代码,可是调试的时候,结果并不完全对,当选中第一行数据的时候,颜色没有变化,从第二行开始颜色会发生变化,求解???GridView改变GridView选中行的颜色asp.net

解决方案 »

  1.   

    protected void GridView1_RowDataBound
    里面还要用
     for (i = 0; i < GridView1.Rows.Count; i++)?这不是画蛇添足吗?
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
          e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='Aqua'");
          e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");    }
    }