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,
- <asp:GridView ID="Grid_FeeCategory" Width="100%" CssClass="table" runat="server" AutoGenerateColumns="False"> <Columns>
- <asp:TemplateField Visible="false">
- <ItemTemplate>
- <asp:label ID="LblCatID" runat="server" Text='<%#Eval("CatID")%>' Visible="false" />
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <HeaderTemplate>
- <asp:CheckBox ID="checkAll" runat="server" onclick="CheckFirstColumnCheckbox(this);" />
- </HeaderTemplate>
- <ItemTemplate>
- <asp:CheckBox ID="chkRow" runat="server" CssClass="1stColOnly" />
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="Disc Cat?">
- <ItemTemplate>
- <asp:CheckBox ID="chkIsForDisc" runat="server" onclick="CheckOne(this)" />
- </ItemTemplate>
- </asp:TemplateField>
-
- <asp:BoundField DataField="CatName" HeaderText="Category" />
- <asp:TemplateField HeaderText="Category Fee" HeaderStyle-Width="125px">
- <ItemTemplate>
- <asp:TextBox ID="txtCat" runat="server" placeholder="Int or Decimal" MaxLength="6" />
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- </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...
- <script type="text/javascript">
- function CheckFirstColumnCheckbox(objRef) {
- var GridView = objRef.parentNode.parentNode.parentNode;
- var spanList = GridView.getElementsByClassName("1stColOnly");
- for (var i = 0; i < spanList.length; i++) {
- var input = spanList[i].childNodes[0];
- if (objRef.checked && !input.disabled) {
- input.checked = true;
- }
- else {
- input.checked = false;
- }
- }
- }
- </script>
-
-
- <script>
- function CheckOne(obj) {
- debugger;
- var grid = obj.parentNode.parentNode.parentNode;
- var inputs = grid.getElementsByTagName("input");
- for (var i = 0; i < inputs.length; i++) {
- if (inputs[i].type == "checkbox") {
- if (obj.checked && inputs[i] != obj && inputs[i].checked) {
- inputs[i].checked = false;
- }
- }
- }
- }
- </script>
I just want to check only one checkbox in 2nd column and multiple in 1st column.
thanks in advance.