title: Select check boxes in gridview using jquery
body: <p>Hi I have gridview which is displaying all the columns and data fine. Problem is there is a check box in the header which when clicked is suppose to check boxes in all rows using jquery.
  However, when i click the header check box rest of the check boxes in the rows of grid wont check. There is some mistake I cant figure out why when I select the header check box it wont select the rest of the check boxes in all rows. Please let me know where the mistake is. </p>
  
  <pre><code> &lt;% @page language="C#" masterPageFile="~/first.master" %&gt;
      &lt;asp:Content ID="xContent" ContentPlaceHolderID="xMainContentContainer" Runat="Server"&gt;
          &lt;script src="js/jquery-1.7.1.min.js" type="text/javascript"&gt;&lt;/script&gt;
              &lt;script type="text/javascript" language="javascript"&gt;
                  $("#&lt;%=GridView3.ClientID%&gt; input[id*='chkAll']:checkbox").click(function () {
                      if ($(this).is(':checked'))
                          $("#&lt;%=GridView3.ClientID%&gt; input[id*='chkEmployee']:checkbox").attr('checked', true);
          else
              $("#&lt;%=GridView3.ClientID%&gt; input[id*='chkEmployee']:checkbox").attr('checked', false);
                  });          
          &lt;/script&gt;
  
         &lt;h1 class="title" id="page-title"&gt;Gridview Page&lt;/h1&gt;       
         &lt;form id="Form" runat="server"&gt;
              &lt;asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
                  BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"  CellPadding="3" CellSpacing="2"&gt;
                  &lt;Columns&gt;
                   &lt;asp:TemplateField&gt;
                  &lt;HeaderTemplate&gt;
                      &lt;asp:CheckBox runat="server" ID="chkAll" /&gt;
                  &lt;/HeaderTemplate&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:CheckBox runat="server" ID="chkEmployee" /&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderText="Id"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="Id" runat="server" Text='&lt;%# Eval("Id") %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderText="Company"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="lblCompany" runat="server" Text='&lt;%# Eval("Company") %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                       &lt;asp:TemplateField HeaderText="Location"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="lblLocation" runat="server" Text='&lt;%# Eval("Location") %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                  &lt;/Columns&gt;
              &lt;/asp:GridView&gt;
          &lt;/form&gt;
      &lt;/asp:Content&gt;
  </code></pre>