Changing color when hover mouse over a row in gridview

September 14, 2011 at 5:59 AMQuang Ngoc

This function for changing color when hover mouse over a row in gridview:

protected void gridCompetence_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowState == DataControlRowState.Alternate)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#A3C952';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#f7fff8';");
            }
            else
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#A3C952';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#eefef0';");
            }
        }
    }

Happy Coding!!!

Posted in: ASP.NET

Tags: ,

blog comments powered by Disqus