Umer Ali

Umer Ali

  • NA
  • 139
  • 6.4k

want to bind drop down using ajax

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

Answers (2)