Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Javascript for Check and uncheck the Checkboxes in gridView</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; var TotalChkBx; var Counter; var TotalUnChkBx; var UnCounter; window.onload = function () { //Get total no. of CheckBoxes in side the GridView. TotalChkBx = parseInt('&lt;%= this.GridView1.Rows.Count %&gt;'); //Get total no. of checked CheckBoxes in side the GridView. Counter = 0; } function HeaderClick(CheckBox) { //Get target base &amp; child control. var TargetBaseControl = document.getElementById('&lt;%= this.GridView1.ClientID %&gt;'); var TargetChildControl = "chkBxSelect"; //Get all the control of the type INPUT in the base control. var Inputs = TargetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes in side the GridView. for (var n = 0; n &lt; Inputs.length; ++n) if (Inputs[n].type == 'checkbox' &amp;&amp; Inputs[n].id.indexOf(TargetChildControl, 0) &gt;= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get target base &amp; child control. var HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if (CheckBox.checked &amp;&amp; Counter &lt; TotalChkBx) Counter++; else if (Counter &gt; 0) Counter--; //Change state of the header CheckBox. if (Counter &lt; TotalChkBx) HeaderCheckBox.checked = false; else if (Counter == TotalChkBx) HeaderCheckBox.checked = true; } &lt;/script&gt; </code></pre> <p>In GridView</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AlternatingRowStyle-BackColor="#006699" AlternatingRowStyle-ForeColor="#FFFFFF" &gt; &lt;Columns &gt; &lt;asp:TemplateField HeaderText="Select"&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="chkBxSelect" runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" /&gt; &lt;ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" /&gt; &lt;HeaderTemplate&gt; &lt;asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" /&gt; &lt;/HeaderTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Serial Number"&gt; &lt;ItemTemplate&gt; &lt;%# Container.DataItemIndex + 1 %&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField HeaderText="Name" DataField="uname" /&gt; &lt;asp:BoundField HeaderText="Pass" DataField="upass"/&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p><strong>Try this One</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload