Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,

How to get the text and value from DropDownCheckBoxes control in asp.net....?

<asp:DropDownCheckBoxes ID="ddllanguage" runat="server" onchange="selectedVal()" AddJQueryReference="True" UseButtons="false" UseSelectAllNode="True"><Style SelectBoxWidth="200" DropDownBoxBoxWidth="200" DropDownBoxBoxHeight="130" />
<texts selectboxcaption="-Select-">


So when i checked the dropdown checkbox that selected values show one textbox.this is my reguriment but i am not getting text and vale .

this is my javascript function
XML
<script type="text/javascript">
          function selectedVal() {
  var a = document.getElementById('<%=ddllanguage.ClientID%>').value;
  alert(a);

</script>

but mu output is empty i am using diifernt script function in all cases same thing will happen ...[lease give a solution .

Regards
Ravinder
Posted
Updated 28-Apr-20 20:30pm
Comments
ZurdoDev 16-Jun-14 10:38am    
Is this what you are reffering to? http://dropdowncheckboxes.codeplex.com/

Also note, it renders lots of individual controls which is why your approach above will not work. If that is what you are using please read its documentation.
ziad imad 16-Jun-14 13:48pm    
do you want to return the value from C# or javascript
SRS(The Coder) 17-Jun-14 1:17am    
The checkbox items mainly rendered as checkbox type input element and labels for it would be next to it. I have added one solution for it please have a look. You can just refer it as per your need.

1 solution

I have crested one test application for your scenario and its working great, please have a look into the below example :-

Controls in my page :
i) A 'asp:DropDownCheckBoxes' control

Ex :-

ASP.NET
<asp:dropdowncheckboxes id="ddllanguage" xmlns:asp="#unknown">
                            runat="server" 
                            onchange="onSelectionChange()"
                            AddJQueryReference="True" 
                            UseButtons="false" 
                            UseSelectAllNode="True"
                            ClientIDMode="Static">
        <style selectboxwidth="200" dropdownboxboxwidth="200" dropdownboxboxheight="130" />
        <texts selectboxcaption="Select Values" />
        <items>
            <asp:listitem text="Test1" value="1"></asp:listitem>
            <asp:listitem text="Test2" value="2"></asp:listitem>
            <asp:listitem text="Test3" value="3"></asp:listitem>
            <asp:listitem text="Test4" value="4"></asp:listitem>
        </items>
    </asp:dropdowncheckboxes>


ii) A textbox to display the selected values
Ex :-
ASP.NET
<asp:textbox runat="server" id="txtValue" clientidmode="Static" xmlns:asp="#unknown"></asp:textbox>


Now the jQuery code to populate the selected checkbox texts into the textbox as comma separated values :-

JavaScript
function onSelectionChange() {
            var selectedVals = '';
            $.each($('#ddllanguage input[type=checkbox]:checked'), function () {
                selectedVals += $("label[for='" + this.id + "']").html() + ",";
            });
            $('#txtValue').val(selectedVals);
        }


NOTE : For getting selected values simply you can concat the 'this.value' to textbox rather than using the above snippet '$("label[for='" + this.id + "']").html()'

The jQuery version used for the example is 1.7.1, you can use accordingly.

Hope this will definitely give you hint how to proceed.
 
Share this answer
 
v2
Comments
Gujula Ravindra Reddy 17-Jun-14 2:36am    
Thanks Smruthi..its working good for me.
SRS(The Coder) 17-Jun-14 3:14am    
If it works fine for you, can you please mark this as answer ?
Leela Prasad R 29-Apr-20 2:31am    
It doesn't work if Select All option is selected.

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