protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                //if (e.Row.RowType==)
                //{
                    e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                //}
            }
        }
问题一:鼠标移动上去时第一条没有改变背景色。我改成int i = -1时第一条改变了背景色。
问题二:if判断不知道怎么写了。
if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
在vs2008中找不到DataControlRowType类。请问是不是改成了其他的类了?

解决方案 »

  1.   

    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='#00A9FF'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");         }
        }这样就可以了。
      

  2.   

     int i;
            //执行循环,保证每条数据都可以更新
            for (i = 0; i < gridview1.rows.count; i++)
            {
                //首先判断是否是数据行
                if (e.row.rowtype == datacontrolrowtype.datarow)
                {
                    //当鼠标停留时更改背景色
                    e.row.attributes.add("over", "c=this.style.backgroundcolor;this.style.backgroundcolor='#00a9ff'");
                    //当鼠标移开时还原背景色
                    e.row.attributes.add("out", "this.style.backgroundcolor=c");
                }
            }