GridView鼠标移动到某一行时行发生变色和为Gridview中编辑模板中的控件添加颜色

 

protected void GvFloorList_RowDataBound(object sender, GridViewRowEventArgs e)//该方法一定要启用RowDataBound事件
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#bcdbec';");
            //当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            //设置悬浮鼠标指针形状为“下手”
            e.Row.Attributes["style"] = "cursor:pointer";

            //设置是否有效颜色样式 ==================================================================================
            Label hidIsValid = e.Row.FindControl("LblIsValid") as Label;
            Label lblIsValidText = e.Row.FindControl("LblIsValidValue") as Label;

            ////有效:绿色
            if (hidIsValid.Text == "1")
            {
                lblIsValidText.ForeColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.Green);
            }
            //无效:红色
            else
            {
                lblIsValidText.ForeColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.Red);
            }
            //======================================================================================================
        }
    }

posted @ 2011-07-29 11:30  haiziguo  阅读(389)  评论(0编辑  收藏  举报