I am developing a country state cascading dropdown list... I returned JSON result based on countryId
but I don't know how to populate/fill it in a new dropdown listbox...
Here is what I am using,
function getstate(countryId) {
$.ajax({
type: "POST",
url: "Reg_Form.aspx/Getstates",
data: "{'countryId':" + (countryId) + "}",
contentType: "application/json; charset=utf-8",
global: false,
async: false,
dataType: "json",
success: function(jsonObj) {
alert(jsonObj.d);
}
});
return false;
}
And alert gave this,
{"Table" : [{"stateid" : "2","statename" : "Tamilnadu"},
{"stateid" : "3","statename" : "Karnataka"},
{"stateid" : "4","statename" : "Andaman and Nicobar"},
{"stateid" : "5","statename" : "Andhra Pradesh"},
{"stateid" : "6","statename" : "Arunachal Pradesh"}]}
And my aspx page has this,
<td>
<asp:DropDownList ID="DLCountry" runat="server" CssClass="dropDownListSkin"
onchange="return getstate(this.value);">
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="DLState" runat="server" CssClass="dropDownListSkin">
</asp:DropDownList>
</td>
Any suggestion on how to fill DLState
dropdown...
EDIT:
When I inspected through firebug I got the response for my AJAX post,
{"d":"{"Table" : [{"stateid" : "2","statename" : "Tamilnadu"},{"stateid" : "3","statename" : "Karnataka"},{"stateid" : "4","statename" : "Andaman and Nicobar"},{"stateid" : "5","statename" : "Andhra Pradesh"},{"stateid" : "6","statename" : "Arunachal Pradesh"},{"stateid" : "7","statename" : "Assam"},{"stateid" : "8","statename" : "Bihar"},{"stateid" : "9","statename" : "Dadra and N. Haveli"},{"stateid" : "10","statename" : "Daman and Diu"},{"stateid" : "11","statename" : "Delhi"},{"stateid" : "12","statename" : "Goa"},{"stateid" : "13","statename" : "Gujarat"},{"stateid" : "14","statename" : "Haryana"},{"stateid" : "15","statename" : "Himachal Pradesh"},{"stateid" : "16","statename" : "Jammu and Kashmir"},{"stateid" : "17","statename" : "Kerala"},{"stateid" : "18","statename" : "Laccadive Islands"},{"stateid" : "19","statename" : "Madhya Pradesh"},{"stateid" : "20","statename" : "Maharashtra"},{"stateid" : "21","statename" : "Manipur"},{"stateid" : "22","statename" : "Meghalaya"},{"stateid" : "23","statename" : "Mizoram"},{"stateid" : "24","statename" : "Nagaland"},{"stateid" : "25","statename" : "Orissa"},{"stateid" : "26","statename" : "Pondicherry"},{"stateid" : "27","statename" : "Punjab"},{"stateid" : "28","statename" : "Rajasthan"},{"stateid" : "29","statename" : "Sikkim"},{"stateid" : "30","statename" : "Tripura"},{"stateid" : "31","statename" : "Uttar Pradesh"},{"stateid" : "32","statename" : "West Bengal"}]}"}
See Question&Answers more detail:
os