Click here to Skip to main content
11,648,960 members (76,174 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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.

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 6-Aug-12 0:35am
Edited 6-Aug-12 0:53am
_Amy53.1K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try following


#GridView1 tr.rowHover:hover
 
    {
 
        background-color: Yellow;
 
        font-family: Arial;
 
    }


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

Please help.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:
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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

  Permalink  
Comments
Deepu S Nair at 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)

  Print Answers RSS
0 F-ES Sitecore 354
1 OriginalGriff 324
2 Kornfeld Eliyahu Peter 309
3 CPallini 295
4 Sergey Alexandrovich Kryukov 254
0 OriginalGriff 1,577
1 Sergey Alexandrovich Kryukov 1,087
2 CPallini 1,015
3 DamithSL 996
4 jyo.net 994


Advertise | Privacy | Mobile
Web02 | 2.8.150804.4 | Last Updated 6 Apr 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100