Introduction
Being as an ASP.NET guy, I always wish to deliver the best apps to the client so that they call WOW!! If you want to highlight the row when user clicks on it and if he clicks on the row again then it removes the highlight. In this article we are going to do that using jQuery.
Look at the screenshot example.

So, let's start developing such a system.
First of all you need to add the reference of your jQuery file in the <head> area. In my case I'm using master page so, I'll place it in ContentPlaceHolder.
<script src="../../../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
Now you need to place the jQuery methods and styles to apply it in grid view. Here is the method code and styles.
<script type="text/javascript">
$(document).ready(function () {
$("tr").filter(function () {
return $('td', this).length && !$('table', this).length
}).click(function () {
$(this).toggleClass('currRow');
});
});
</script>
<style type="text/css">
.currRow
{
background-color:#CCCCCC;
cursor:pointer;
}
</style>
In above style I'm using #CCCCCC color code to highlight the row. Now look at the complete code that I'll be using.
Complete Code
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Profile_Office_2012_Finder_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<script src="../../../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("tr").filter(function () {
return $('td', this).length && !$('table', this).length
}).click(function () {
$(this).toggleClass('currRow');
});
});
</script>
<style type="text/css">
.currRow
{
background-color:#CCCCCC;
cursor:pointer;
}
</style>
</asp:Content>

Join the conversation! Your thoughts help the community grow.