Checking all checkboxes in list by single checkbox click
<p>On my webpage, I have a CheckBoxList and a single checkbox. When I click on the check box, all the Check Boxes in the CheckBoxList should get checked. My CheckBoxList has to be under Bodycontent placeholder because that's how the layout of webpage is, and I kept the script in the same placeholder.</p>

<pre><code>&lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
&lt;script type="text/javascript"&gt;
            function select(ch) {
                var allcheckboxes = document.getElementById('&lt;%=CheckBoxList1.ClientID %&gt;').getElementsByTagName("input");
                for (i = 0; i &lt; allcheckboxes.length; i++)
                    allcheckboxes[i].checked = ch.checked;
            }
        &lt;/script&gt;

        &lt;asp:CheckBoxList ID="CheckBoxList1" runat="server" 
            RepeatDirection="Horizontal" RepeatLayout="Flow"&gt;
            &lt;asp:ListItem&gt;Item A&lt;/asp:ListItem&gt;
            &lt;asp:ListItem&gt;Item B&lt;/asp:ListItem&gt;
            &lt;asp:ListItem&gt;Item C&lt;/asp:ListItem&gt;
        &lt;/asp:CheckBoxList&gt;

            &lt;asp:CheckBox ID="allCheck" onclick="select(this)" runat="server" Text="Select all" /&gt;
                &lt;br /&gt;
&lt;/asp:Content&gt;
</code></pre>

<p>The above doesn't do anything. On clikcing on the checkbox nothing happens! I have been stuck on this small issue from quite long and not able to do the same. Any suggestions what's wrong?</p>
