javascript - Select All CheckBoxes in GridView ASP.NET using JQuery -


I have a check box called "Category A" and "Category B" in my Gridview Temple column. I want to select all the functionality, that is, when the user checks all check boxes in the selection in the Category A column, then all the checkboxes must be checked under that column. Also for Category B I am trying with the code below. The problem with my code is that it selects all the check boxes in the entire gridview, "Category A" as well as the "Category B" checkbox. But, I have to select only the checkbox under the same column.

  function Select AllCheckboxesA (chk) {$ ('# & lt;% = gvSurveys.ClientID% & gt;'). ("Input: check box"). Each (function () {if (this! = Chk) {if ($ (this) .hasClass ('CatA')! = False} {this.checked = chk.checked;}} else {alert ($ (this) );}}); } & Lt; Asp: GridView id = "gvSurveys" runat = "server" AutoGenerateColumns = "false" allow = "true" width = "1500px" & gt; & Lt; Columns & gt; & Lt; ASP: TemplateField & gt; & Lt; HeaderTemplate & gt; Category A & amp; Lt; Asp: checkbox id = "chkSelectAllCatA" runat = "server" visible = "wrong" onclick = "javascript: select all checkboxes (this);" CssClass = "SACATA" /> & Lt; / HeaderTemplate & gt; & Lt; ItemTemplate & gt; & Lt; Asp: checkbox id = "chkCatA" runat = "server" enabled = "wrong" CssClass = "CatA" /> & Lt; / ItemTemplate & gt; & Lt; / ASP: TemplateField & gt; & Lt; ASP: TemplateField & gt; & Lt; HeaderTemplate & gt; Category B & lt; Asp: checkbox id = "chkSelectAllCatB" runat = "server" visible = "false" CssClass = "CatB" onclick = "javascript: SelectAllCheckboxesB (this);" / & Gt; & Lt; / HeaderTemplate & gt; & Lt; ItemTemplate & gt; & Lt; Asp: check box id = "chkCatB" runat = "server" enabled = "wrong" /> & Lt; / ItemTemplate & gt; & Lt; / ASP: TemplateField & gt; & Lt; / Column & gt; & Lt; / ASP: GridView & gt;  

Based on this solution, proposed by some modifications to clear the checkbox in the harnesser row When any of the grid lines are unchecked, the checkbox is unchecked.

Create a template column in the gridview:

  & lt; Asp: templatefield & gt; & Lt; HeaderTemplate & gt; & Lt; Asp: check box id = "chkSelectAll" cssclass = "chkHeader" runat = "server" /> & Lt; / HeaderTemplate & gt; & Lt; ItemTemplate & gt; & Lt; Asp: checkbox id = "chkSelect" cssclass = "chkItem" runat = "server" /> & Lt; / ItemTemplate & gt; & Lt; / ASP: TemplateField & gt;  

jquery script, put it in $ (document). For example:

  var Headfix = $ (". ChkHeader input"); Var Madchuck = $ (". ChkItem Input"); Helperchuck.click (function () {itemChk.each (function () {this.checked = headerChk [0]. Checked;})}); ItemChk.each (function () {$ (this). Click (function () {if (this.checked == false) {HeaderChurch [0]. Checked = false;}})});  

Comments