Click here to Skip to main content
15,889,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to bind checkbox list inside dropdownlist.
Suppose we are checking two checkbox inside dropdownlist
so on the behalf of checking we have to bind otherdropdown.

Example: Like in 1st dropdown we are checking US and UK country so we have to bind state dropdown on behalf of country dropdown but we might select more than one country at a time through checkbox.
Posted
Comments
Gaurav Makwana 13-Dec-13 4:41am    
just use combobox and bind value of combobox
rummer 13-Dec-13 4:59am    
We have to take checkbox list inside dropdown so may select more than one
Gaurav Makwana 13-Dec-13 23:25pm    
just see property of dropdown list see all property in msdn

 
Share this answer
 
Comments
rummer 13-Dec-13 4:58am    
No, This is different my requirement is binding two drop down
With the help of Jquery and WebMethod you can achieve this:-

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>

    <script type="text/javascript" language="javascript">
        $(function() {
            var stuff = [];
            $('.multiselect input[type="checkbox"]').change(function() {
                if ($(this).is(':checked')) {
                    var element = $(this).val();
                    stuff.push(element);
                    // alert(stuff);
                }
                else {
                    var element = $(this).val();
                    //stuff.pop(element);
                    stuff = jQuery.grep(stuff, function(data) {
                        return data != element;
                    });
                    //   alert(stuff);
                }
                var sdata = {};
                sdata.stuff = stuff;
                $.ajax({
                    url: '../WebService/FirstService.asmx/CasCadeDDL',
                    type: 'POST',
                    cache: false,
                    dataType: 'json',
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify(sdata),
                    success: function(data) {
                        $('#ddlState').html(data.d);
                    }

                });
            });
        });
    </script>

    <style type="text/css">
        .multiselect
        {
            width: 7em;
            height: 5em;
            border: solid 1px #c0c0c0;
            overflow: auto;
        }
        .multiselect label
        {
            display: block;
        }
        .multiselect-on
        {
            color: #ffffff;
            background-color: #000099;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="multiselect">
        <label>
            <input type="checkbox" value="1" />US</label>
        <label>
            <input type="checkbox" value="2" />UK</label>
        <label>
            <input type="checkbox" value="3" />India</label>
        <label>
            <input type="checkbox" value="4" />Australia</label>
    </div>
    <br />
    <br />
    <select id="ddlState">
    </select>
    </form>
</body>
</html>



Now, the WebMethod code written in the webservice:-

C#
[WebMethod]
    public string CasCadeDDL(string[] stuff)
    {
        string conn = ConfigurationManager.ConnectionStrings["con_str"].ConnectionString;
        string _str = string.Empty;
        StringBuilder sb = new StringBuilder();
        using (SqlConnection con = new SqlConnection(conn))
        {
            SqlCommand cmd = con.CreateCommand();
            string _search = string.Join(", ", stuff);
            cmd.CommandText = "SELECT state FROM Country_State where CountryId in ("+_search+")";
            cmd.CommandType = CommandType.Text;
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                sb.Append("<option>" + dr[0].ToString() + "</option>");
            }
            _str = sb.ToString();
        }
        return _str;
    }


Hope, this will helps you....Please ask for further queries...
 
Share this answer
 
v2

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