Here i have explained how to Highlight row if checkbox is checked in gridview Asp.Net C#.

Step 1) Add HTML:

<asp:GridView ID="GridView1" runat="server">
<HeaderStyle BackColor="#ff9933" Font-Bold="true" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkChild"  runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Step 2) CSS

.highlightRow { background-color:Green; Color:White; }

Step 3) Attach JavaScript File

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">

Step 4) Add JavaScript

$(document).ready(function () {
// Header Checkbox click function
$('[id$=chkHeader]').click(function () {
if ($('[id$=chkHeader]:checked').length > 0) {
$('[id$=chkChild]').parent().parent().addClass('highlightRow');
}
else {
$('[id$=chkChild]').parent().parent().removeClass('highlightRow');
}
$("[id$=chkChild]").attr('checked', this.checked);
});
// Child Checkbox click function
$("[id$=chkChild]").click(function () {

if (this.checked) {
$(this).parent().parent().addClass('highlightRow');
}
else {
$(this).parent().parent().removeClass('highlightRow');
}

if ($('[id$=chkChild]').length == $('[id$=chkChild]:checked').length) {
$('[id$=chkHeader]').attr("checked", "checked");
}
else {
$('[id$=chkHeader]').removeAttr("checked");
}
});
});

Step 5) Import Namespaces

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

Step 6) C#

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridview();
        }
    }
    // Bind gridview from database
    protected void BindGridview()
    {
        string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

        using (SqlConnection con = new SqlConnection(strConnString))
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "select TOP 6 Name,City,Country from Students";
                cmd.Connection = con;
                con.Open();
                GridView1.DataSource = cmd.ExecuteReader();
                GridView1.DataBind();
                con.Close();
            }
        }
    }

Screenshot

Add Comments