Rameez Javed

Rameez Javed

  • NA
  • 395
  • 62.1k

Specific Column's Single Checkbox Checked

Apr 13 2020 8:24 AM
Hi, I've a gridview with two columns with checkboxes, In 1st Column I'm checking multiple columns but in 2nd column i just want to check single row, 
  1. <asp:GridView ID="Grid_FeeCategory" Width="100%" CssClass="table" runat="server" AutoGenerateColumns="False">      <Columns>  
  2.        <asp:TemplateField Visible="false">  
  3.            <ItemTemplate>  
  4.                 <asp:label ID="LblCatID" runat="server" Text='<%#Eval("CatID")%>' Visible="false" />  
  5.            </ItemTemplate>  
  6.        </asp:TemplateField>  
  7.        <asp:TemplateField>  
  8.            <HeaderTemplate>  
  9.                <asp:CheckBox ID="checkAll" runat="server" onclick="CheckFirstColumnCheckbox(this);" />  
  10.            </HeaderTemplate>  
  11.            <ItemTemplate>  
  12.                 <asp:CheckBox ID="chkRow" runat="server" CssClass="1stColOnly" />  
  13.            </ItemTemplate>  
  14.        </asp:TemplateField>  
  15.        <asp:TemplateField HeaderText="Disc Cat?">  
  16.            <ItemTemplate>  
  17.                <asp:CheckBox ID="chkIsForDisc" runat="server" onclick="CheckOne(this)" />  
  18.            </ItemTemplate>  
  19.        </asp:TemplateField>  
  20.                                               
  21.        <asp:BoundField DataField="CatName" HeaderText="Category" />  
  22.        <asp:TemplateField HeaderText="Category Fee" HeaderStyle-Width="125px">  
  23.           <ItemTemplate>  
  24.                <asp:TextBox ID="txtCat" runat="server" placeholder="Int or Decimal" MaxLength="6" />  
  25.           </ItemTemplate>  
  26.        </asp:TemplateField>  
  27.        </Columns>  
  28.    </asp:GridView>  
 Above is the grid and below I'm using the jquery functions, the checkone is ambigious it unchecks the other column checkbox too... 
  1.   <script type="text/javascript">  
  2.         function CheckFirstColumnCheckbox(objRef) {  
  3.             var GridView = objRef.parentNode.parentNode.parentNode;  
  4.             var spanList = GridView.getElementsByClassName("1stColOnly");  
  5.             for (var i = 0; i < spanList.length; i++) {  
  6.                 var input = spanList[i].childNodes[0];  
  7.                 if (objRef.checked && !input.disabled) {  
  8.                     input.checked = true;  
  9.                 }  
  10.                 else {  
  11.                     input.checked = false;  
  12.                 }  
  13.             }  
  14.         }  
  15. </script>  
  16.   
  17.   
  18. <script>  
  19.     function CheckOne(obj) {  
  20.         debugger;  
  21.         var grid = obj.parentNode.parentNode.parentNode;  
  22.         var inputs = grid.getElementsByTagName("input");  
  23.         for (var i = 0; i < inputs.length; i++) {  
  24.             if (inputs[i].type == "checkbox") {  
  25.                 if (obj.checked && inputs[i] != obj && inputs[i].checked) {  
  26.                     inputs[i].checked = false;  
  27.                 }  
  28.             }  
  29.         }  
  30.     }  
  31. </script>  
I just want to check only one checkbox in 2nd column and multiple in 1st column.

thanks in advance.

Answers (2)