Click here to Skip to main content
15,299,443 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have 3 checkbox on the page named (setup ,employee, salary) and have 4 options for setup that are as follows company ,branch, designation, department. And for these i have taken a checkboxlist in that I have added these items. And I want that if i will check any item in checkboxlist then set checkbox should be checked and if we unchecked all the items of checkboxlist then it (checkbox for setup) should be unchecked.
Updated 9-Nov-11 2:18am
Anuja Pawar Indore 9-Nov-11 8:19am
Spelling mistakes corrected

You need to use Javascript. This is the same functionality like "check all"

call following javscript on setup checkbox click, it will select items of setup checkbox checked.

function CheckBoxListSelect()
       var chkBoxList = document.getElementById("chkBoxList1");
        var chkBoxCount= chkBoxList.getElementsByTagName("input");
        for(var i=0;i<chkboxcount.length;i++)>
            if (chkBoxCount[i].checked)
                chkBoxCount[i].checked = false;
                chkBoxCount[i].checked = true;
        return false; 
Member 8387468 9-Nov-11 6:33am
can u provide me code on selectedindexchanged event of checkboxlist

Here i tried some code for your requirement just check this once

<html xmlns="">
<head runat="server">
    <script language ="javascript" >
        function f1(ti) {
            var str = new String();
            str = ti;
            var str1 = str.split('_');
            var len = document.getElementById(str1[0]).rows.length;
            var asd = 0;
            for (var i = 0; i < parseInt(len); i++) {
                if (document.getElementById(str1[0]+'_'+i).checked) {
                    asd = 1;
            if (asd == 1) {
                document.getElementById("CheckBox1").checked = true;
            else {
                document.getElementById("CheckBox1").checked = false;
    <form id="form1" runat="server">
        <asp:checkbox id="CheckBox1" runat="server" xmlns:asp="#unknown" />
        <asp:checkboxlist id="CheckBoxList1" runat="server" xmlns:asp="#unknown">
           <asp:listitem text="first" value="first" onclick="f1("></asp:listitem>
           <asp:listitem text="secnd" value="secnd" onclick="f1("></asp:listitem>
           <asp:listitem text="third" value="third" onclick="f1("></asp:listitem>
           <asp:listitem text="forth" value="forth" onclick="f1("></asp:listitem>

I hope it works for you too

All the Best

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900