Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hello,

I have 3 different dropdownlists (<select> tag) in my webform, now i don't want to use asp.net postbacks/codebehind to populate them.The first list pre-populated with the names of countries in the world. Now I want to use asp.net web methods (returns json) and jQuery to populate the STATES list based on the country selected (on list.change jQuery event) and so on for the CITY list. Pleas help.

Thanks
Posted
Comments
Sampath Lokuge 26-Nov-13 14:14pm    
Check this link :http://www.codeproject.com/Answers/688258/Appending-data-to-dropdownlist-box-in-JQuery#answer1

1 solution

You need to select the dropdown and onchange event u'll need to call a webservice and pu tthe result on the next dropdown. That's it.....for example


$('.ddlCountry').bind('change', function () {
var CountryId = $('.ddlCountry').val();
FillStates(CountryId);
}

FillStates = function(CountryId)
{
$.ajax({
url: 'Webservice url', // Webservice gives the states result on the basis of CountryId//
type: 'POST',
cache: false,
dataType: 'json',
data: {CountryId:"'+CountryId+'"},
contentType: 'application/json; charset=utf-8',
success: function (result) {
if (result.d){
$('.ddlStates').val(result.d);
}
}
});


Your problem will be solved. Please feel free to ask for any clarifications.
 
Share this answer
 

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