Click here to Skip to main content
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 1:35am
Edited 6-Aug-12 1:53am
_Amy51.3K
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  

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 295
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 6 Aug 2012
Copyright © CodeProject, 1999-2014
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