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.
Posted
Updated 9-Nov-11 2:18am
v2
Comments
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.

JavaScript
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;
            else
                chkBoxCount[i].checked = true;
        }
        
        return false; 
}
   
Comments
Member 8387468 9-Nov-11 6:33am
   
can u provide me asp.net code on selectedindexchanged event of checkboxlist
Hi,

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

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <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;
            }
           
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <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(this.id)"></asp:listitem>
           <asp:listitem text="secnd" value="secnd" onclick="f1(this.id)"></asp:listitem>
           <asp:listitem text="third" value="third" onclick="f1(this.id)"></asp:listitem>
           <asp:listitem text="forth" value="forth" onclick="f1(this.id)"></asp:listitem>
        </asp:checkboxlist>
    </div>
    </form>
</body>
</html>


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