126 how to bind dropdownlist in asp net using jquery or JSON

Video ready, click here to close ×


126.In previous articles I explained Bind gridview using JQuery in asp.net and AutoComplete textbox with JQuery using asp.net. Now I will explain how to bind dropdownlist using JQuery or JSON in asp.net.
To implement this concept first design table in database and give name as Country as shown below
Column Name
Data Type
Allow Nulls
CountryId
int(set identity property=true)
No
CountryName
varchar(50)
Yes
After completion table design enter some of Country details in database to work for our sample and write the following code in your aspx page

Function :
$(document).ready(function() {
$.ajax({
type: “POST”,
contentType: “application/json; charset=utf-8”,
url: “Default.aspx/BindDatatoDropdown”,
data: “{}”,
dataType: “json”,
success: function(data) {
$.each(data.d, function(key, value) {
$(“#ddlCountry”).append($(“option/option”).val(value.CountryId).html(value.CountryName));
});
},
error: function(result) {
alert(“Error”);
}
});
}); Follow Us On
Facebook : www.facebook.com/yoctokarthi
Twitter : www.twitter.com/yoctokarthi
Google Plus : https://plus.google.com/+YoctoKarthi
HackerRank : www.hackerrank.com/yoctokarthi
Instagram : www.instagram.com/yoctokarthi

source

Leave a Reply

Your email address will not be published. Required fields are marked *