With the help of Jquery and WebMethod you can achieve this:-
<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:-
[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...