How to populate a dropdownlist with json data in jquery?
Posted
by Pandiya Chendur
on Stack Overflow
See other posts from Stack Overflow
or by Pandiya Chendur
Published on 2010-04-14T13:28:43Z
Indexed on
2010/04/14
13:33 UTC
Read the original article
Hit count: 224
I am developing a country state cascading dropdown list... I returned json result based on countryId
but i dont 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 is,
<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 how to fill it DLState
dropdown...
© Stack Overflow or respective owner