javascript - header checkbox not working first click -


hey have 2 view

1- index 2- edit 

i have grid header have 1 checkbox want click checkbox rows checkbox checkbox. in header checkbox not working first time when click uncheck check work fine. dont know why , problem in code please help

here index view have script

         function check_uncheck() {             $('#selectall').click(function () {                 if (this.checked) {                     $('.checkbox:enabled').each(function () {                         this.checked = true;                     });                 }                 else {                     $('.checkbox:enabled').each(function () {                         this.checked = false;                     });                 }             });         } 

and here edit have checkbox

<input type="checkbox" id="selectall" onclick="check_uncheck();" tabindex="3" /> 

if want select , unselect checkboxes of gridview row, can below:-

<script type="text/javascript">     function selectall(obj) {         var valid = false;         var chkselectcount = 0;         var gridview = document.getelementbyid('<%= gridview1.clientid %>');         (var = 0; < gridview.getelementsbytagname("input").length; i++) {             var node = gridview.getelementsbytagname("input")[i];             if (node != null && node.type == "checkbox") {                 node.checked = obj;             }         }         return false;     } </script> 

gridview aspx:-

<asp:gridview id="gridview1"                     runat="server" autogeneratecolumns="false"></asp:gridview> 

and onbutton click

     select :                  <asp:linkbutton id="lnkdelete" runat="server" causesvalidation="false" text="all" onclientclick="selectall(true); return false"></asp:linkbutton>                     |                  <asp:linkbutton id="lnkundelete" runat="server" causesvalidation="false" text="none" onclientclick="selectall(false); return false"></asp:linkbutton> 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -