All we need to do is that on mouseover on gridview rows assign any CSS and on mouseout, remove that CSS. Rather than using mouseover and mouseout method seperately, jQuery provides another method named "hover()" which serves purpose of both the methods. Please read more here abouthover().
Below jQuery code, will find all the rows of gridview and using hover method it will assign "LightGrey" color on mouseover and then assign "White" color on mouseout.
1 | $(document).ready( function () { |
2 | $( "#<%=gdRows.ClientID%> tr" ).hover( function () { |
3 | $( this ).css( "background-color" , "Lightgrey" ); |
4 | }, function () { |
5 | $( this ).css( "background-color" , "#ffffff" ); |
6 | }); |
7 | }); |
But there is a problem with this code. That is it will assign the mouseover and mouseout effect on header row as well. Try it yourself with above code. So how to resolve it? Well, we need to change above code little bit so that it finds only those rows which are having "td", not "th". To do this, we can use "has" selector of jQuery to find out all the rows which have td. See below jQuery code.
1 | $(document).ready( function () { |
2 | $( "#<%=gdRows.ClientID%> tr:has(td)" ).hover( function () { |
3 | $( this ).css( "background-color" , "Lightgrey" ); |
4 | }, function () { |
5 | $( this ).css( "background-color" , "#ffffff" ); |
6 | }); |
7 | }); |
source : http://jquerybyexample.blogspot.com/2011/06/highlight-row-on-mouseover-in-gridview.html
No comments:
Post a Comment