<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/themes/blitzer/jquery-ui.css"
rel="Stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("[id$=txtCountry]").autocomplete({
source: function (request, response) {
$.ajax({
url: '<%=ResolveUrl("~/NewTheme/Default.aspx/GetCountry") %>',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('-')[0],
val: item.split('-')[1]
}
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
$("[id$=hfId]").val(i.item.val);
},
minLength: 1
});
});
</script>
[WebMethod]
public static string[] GetCountry(string prefix)
{
clsDataAccess ObjData = new clsDataAccess();
string SS = "";
List<string> Country = new List<string>();
SS = "select DISTINCT Name, Id from Country where Name like '" + prefix + "' + '%'";
SqlDataReader dr = ObjData.GetReader(SS);
while (dr.Read())
{
Country.Add(string.Format("{0}--{1}", dr["Name"], dr["Id"]));
}
return Country.ToArray();
}