Hello i want to Bind Drop down using ajax in asp.net , but it is not working
plz help me
see my code:
- $(document).ready(function () {
- debugger;
- $.ajax({
- type: "POST",
- url: "~/Settings/City.aspx/BindCountry",
- data: '{}',
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- sucess: function (r) {
- var ddlcountrry = $("[id*=MainContent_ddlCountry]");
- ddlcountrry.empty().append('<option selected="selected" value="0">Please select</option>');
- $.each(r.d, function () {
- ddlcountrry.append($("<option></option>").val(this['Value']).html(this['Text']));
- });
- },
- failure: function () {
- alert("Failed!");
- }
- });
- });
- [WebMethod]
- public List<ListItem> BindCountry()
- {
- DataSet dsCountry = ObjGlobalBll.FetchCountry(ObjGlobal);
- DataTable dt = dsCountry.Tables[0];
-
- List<ListItem> Country = new List<ListItem>();
- foreach (DataRow dr in dt.Rows)
- {
- Country.Add(new ListItem
- {
- Text = dr["CountryName"].ToString(),
- Value = dr["CountryID"].ToString()
- });
- }
- return Country;