Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

Typically we will attach the mouseover and mouseout client-side events on the gridview rows to highlight rows on mouseover, but there are cases that we don't want to make the row highlighted when we are on edit mode. To do this we can check the GridView EditIndex to determine if the row is on edit mode and then do the validation there. Here's a sample code block below of what I am talking about:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
            if (e.Row.RowType == DataControlRowType.DataRow) {
                string onmouseoverStyle = "this.style.backgroundColor='blue';this.style.color ='white';";
                string onmouseoutStyle = "this.style.backgroundColor='white';this.style.color ='black';";

                if (GridView1.EditIndex != -1) {
                    e.Row.Attributes.Remove("onmouseover");
                }
                else {
                    e.Row.Attributes.Add("onmouseover", onmouseoverStyle);
                    e.Row.Attributes.Add("onmouseout", onmouseoutStyle);
                }
            }
}

As you can see the code above is very straight forward. What it does is it checks if the gridview is on edit mode and when it's on edit mode we removed the onmouseover attribute and when it's not we attach the onmouseover attribute again and apply the desired styles. That's simple!


I hope someone find this post useful!

Technorati Tags: ,,
Posted on Tuesday, April 26, 2011 2:17 PM ASP.NET , C# , GridView | Back to top


Comments on this post: Tip Of The Day - Remove GridView Row Highlighting on Edit Mode

# re: Tip Of The Day - Remove GridView Row Highlighting on Edit Mode
Requesting Gravatar...
Nice Article...
Thanx for posting. I like your blog.. Its great!

I have two textbox and two button(Next and Previous). i want that when i click on Next or Prev button it show me table next or prev value in textbox.

and also bind gridview and show gridview next or prev row highlighted...
please help...

Thanx
Left by Vishal on Nov 13, 2011 3:18 AM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net