This blog is containing detailed information about DropDownList with jQuery. To Bind DropDownList in jQuery We have to write below code in <script> block.
<script type="text/javascript">
function CallService() {
var txtValue = $("#TextBox1").val();
$.ajax({
type: "POST", //GET or POST or PUT or DELETE verb
url: "Service.svc/getCityList", // Location of the service
data: '{"str": "' + txtValue + '"}', //Data sent to server
contentType: "application/json; charset=utf-8", // content type sent to server
dataType: "json", //Expected data format from server
processdata: true, //True or False
success: function (msg) {//On Successfull service call
if (msg.getCityListResult == '') {
$("#divCity").html("No Data found");
}
else {
var ddl = $('#ddlCity');
ddl.append("<option value='0'>-select-</option>");
for (var i = 0; i < msg.getCityListResult.length; i++) {
var City = msg.getCityListResult[i].split('~')[0];
var Code = msg.getCityListResult[i].split('~')[1];
ddl.append("<option value='" + Code + "'>" + City + "</options>");
}
}
}
});
}
</script>
With the above code you get all city name and code against State name.
If the state name not exist in the database,
divCity(div id) shows "No Data found".
Write below code in WCF .cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
using System.Data.SqlClient;
using System.Data;
// NOTE: If you change the class name "Service" here, you must also update the reference to "Service" in Web.config.
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
public class Service : IService
{
SqlConnection cn = new SqlConnection("Data Source=BCILGGN13\\SQLEXPRESS;
Initial Catalog=Test; Uid=sa; Pwd=bcil; ");
SqlDataAdapter adap;
DataTable dt;

Join the conversation! Your thoughts help the community grow.