C# ASP.net GridView中当鼠标移入或移出某行时,该行变色

protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            int i;
            for (i = 0; i < GridView1.Rows.Count + 1; i++) // 网上代码这里没有加1,发现当移入移出第一行时颜色未变。
            {
                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");
                }
            }
        }

 

截图00

   单击GridView控件,显示属性窗口,点击事件按钮,找到RowDataBound事件,然后   设计方法。

posted @ 2009-08-27 14:30  斑点海豚---寂静的港湾  阅读(506)  评论(0)    收藏  举报