Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Frnds,

our project is based upon ASP.NET, Gridview, C#, SqlServer 2005.

I need to change the color of row on Mouseover.

already am using background color for 2 columns in my gridview.

and i wrote code in row databound event....this is my code.

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {

        e.Row.Attributes.Add("onmouseover",
        "this.originalcolor=this.style.backgroundColor;" + " this.style.backgroundColor='#FDCB0A';");

        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalcolor;");
 
    }
}


This is working fine, BUT when i mouseover, this mouseover color is not showing on that two columns in gridview(which i have gave another background color to them)

So my requirement is when i mouseover on row.., that particular row INCLUDING that two columns(which i have gave Background color) must also change the color on Mouseover


Please help.

Thanks in advance.
Posted
Updated 6-Aug-12 0:53am
v3

Try following


CSS
#GridView1 tr.rowHover:hover

   {

       background-color: Yellow;

       font-family: Arial;

   }



ASP.NET
<asp:gridview id="GridView1" runat="server" enableviewstate="false" rowstyle-cssclass="rowHover" clientidmode="Static" xmlns:asp="#unknown" />
 
Share this answer
 
Comments
Ranjith Reddy CSE 6-Aug-12 6:47am    
Sorry boss , its not working

Please help.
Hi,
Add two more attributes, 1st remove the background color of particular cell on mouse hover and then add the previews background color on mouse out. Then only this parent style will work. Try this:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // Remove your cell style here
        GridViewRow s = (GridViewRow)e.Row;
        s.Cells[5].Attributes.Add("onmouseover", "oDiv.style.removeProperty('background-color');");
        //Add your cell style here
        s.Cells[5].Attributes.Add("onmouseout", "oDiv.style.background-color=#FFFF");

        e.Row.Attributes.Add("onmouseover",               "this.originalcolor=this.style.backgroundColor;" + " this.style.backgroundColor='#FDCB0A';");
         
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalcolor;");

    }
}



--amit
 
Share this answer
 
 
Share this answer
 
Comments
Deepu S Nair 6-Apr-15 9:42am    
Did you notice that this question is nearly 3 years old ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900