Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to show in checkboxlist the selected checkbox index in a label each time when i select diffrent checkbox in checkboxlist. how can i do it?
Posted
Updated 15-Apr-14 1:30am
v2
Comments
[no name] 15-Apr-14 7:34am    
What have you tried? What happened when you ran your code? What errors did you get?
TCS54321 18-Apr-14 3:59am    
in my checkboxlist there are some classes like 1-b.tech(cse) 2-b.tech(it) 3-b.tech(ece) 4-b.tech(me) when i select when i select b.tech(ece) it give the correct classid of b.tech(ece) and then i select b.tech(me) it give the classid of b.tech(me) again if i select b.tech(it) or b.tech(cse) then it give right classid. basically it pick the first selected classid in cleckbox list. how can i pick the current selected classid on each selection?

1 solution

Use JavaScript, see example:
XML
<script type="text/javascript" language="javascript">
        function showCheckedBoxId() {
            var checkboxlist = document.getElementById('<%= CheckBoxList1.ClientID%>');
            var label = document.getElementById('<%= Label1.ClientID%>');
            label.innerHTML = "You have selected ";
            var checkBoxes = checkboxlist.getElementsByTagName("input");
            for (i = 0; i < checkBoxes.length; i++) {
                if (checkBoxes[i].checked) label.innerHTML = label.innerHTML + " " + checkBoxes[i].id;
            }
            return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBoxList ID="CheckBoxList1" runat="server" onchange="return showCheckedBoxId()">
            <asp:ListItem>ASP.NET</asp:ListItem>
            <asp:ListItem>C#</asp:ListItem>
            <asp:ListItem>VB.NET</asp:ListItem>
            <asp:ListItem>PHP</asp:ListItem>
            <asp:ListItem>HTML</asp:ListItem>
        </asp:CheckBoxList>
        <br />
        <asp:Label ID="Label1" runat="server"></asp:Label></div>
    </form>
 
Share this answer
 
Comments
TCS54321 17-Apr-14 1:13am    
in my checkboxlist there are some classes like
1-b.tech(cse) 2-b.tech(it) 3-b.tech(ece) 4-b.tech(me)

when i select when i select b.tech(ece) it give the correct classid of b.tech(ece) and then i select b.tech(me) it give the classid of b.tech(me) again if i select b.tech(it) or b.tech(cse) then it give right classid. basically it pick the first selected classid in cleckbox list. how can i pick the current selected classid on each selection?

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