In this Video I am going to explain with example How to fill/populate asp.net dropdown list dynamically from sql server database by calling C# server side code from client side using jquery AJAX and json.
Thank you very much. but I have a question if I want to bind the data from service how I can change it?? Example public void GetAgencyNames() { var listOfAgencyNames = UserProfileService.GetAgencyNames(agencyNAMEVO); DropDownAgencyName.DataSource = listOfAgencyNames; DropDownAgencyName.DataValueField = "AgencyName"; DropDownAgencyName.DataTextField = "AgencyName"; DropDownAgencyName.DataBind(); DropDownAgencyName.Items.Insert(0, new ListItem("Please select a value", "")); } Please help.. Thanks
I tried this one before watching this,the same way I bind ddl with Ajax...and work out for me, but after that in save button I have to save the ddl value to the db table, but I get the selected value as empty...I stuck with this today...🤔
Can you please provide the script of the code because I am unable to get the code and I have having two column in a table States and country so is it necessary to have ID column also.I want to populate the States only and on the basis of selection of State in Dropdownlist I need to pupulate the Cities name in the checkboxlist and that checkboxlist should be bind from database.Can you please help me on this.Thanks
hi sir can u provide code like if i am select picture of state there city picture is open.if i select city picture there area picture will display.the query is like state?cityid=1.please sir provide this code.
step 1 step2 step 3 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Web.Services; public partial class AjaxDataBlindDropDown : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } public class cierre { public string idCierreInd { get; set; } public string Cierre { get; set; } } [WebMethod] public static List ddl() { DataTable dt = new DataTable(); String CS = ConfigurationManager.ConnectionStrings["t3Procesos"].ConnectionString; List objDept = new List(); using (SqlConnection con = new SqlConnection(CS)) { using (SqlCommand cmd = new SqlCommand("SELECT TOP 100 idCierreInd,Cierre from [t3Procesos].dbo.m_cierreIndividual", con)) { con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { objDept.Add(new lcierre { idCierreInd = dt.Rows[i]["idCierreInd"].ToString(), Cierre = dt.Rows[i]["Cierre"].ToString() }); } } return objDept; } } } } step 4 $(document).ready(function(){ $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "AjaxDataBlindDropDown.aspx/ddl", data: "{}", dataType: "json", success: function (result) { $('#DropDownList1').empty(); $('#DropDownList1').append("--Select--"); $.each(result.d, function (key,value) { $('#DropDownList1').append($("").val(value.idCierreInd).html(value.Cierre)); }); }, failure: function ajaxError(result) { alert(result.status +':'+ result.statusText); } }); });