Hi All
I am building a web API for Address.
If a user enters postcode , the rest of the text boxes should be populated with the correct values.
I have done something but the complete address is showing in one single text box.
Can please some one help me
.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AutoCompletetextBox.aspx.cs" Inherits="AutoTextBox.AutoCompletetextBox" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AutoComplete Textbox with webservice using jQuery</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "AutoCompleteService.asmx/GetAutoCompleteData",
data: "{'postcode':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Please Enter Valid PostCode");
}
});
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="demo">
<div class="ui-widget">
<label for="tbAuto">Post Code: </label>
<input type="text" id="txtSearch" class="autosuggest" /><br />
<label for="tbAuto">Building Number: </label>
<input type="text" id="txtSearch1" class="autosuggest" /><br />
<label for="tbAuto">Building Name: </label>
<input type="text" id="txtSearch2" class="autosuggest" />
</div>
</div>
</form>
</body>
</html>
.
namespace AutoTextBox
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class AutoCompleteService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public List<string> GetAutoCompleteData(string postcode)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=Test;Integrated Security=True"))
{
using (SqlCommand cmd = new SqlCommand("select (CAST(ISNULL(BuildingNumber,0) AS NVARCHAR(20)) +' '+ ISNULL(BuildingName,'') +' '+ ISNULL(Postcode,'')) as CompleteAddress from AddressRecord where( CAST(ISNULL(BuildingNumber,0) AS NVARCHAR(20)) +' '+ ISNULL(BuildingName,'') +' '+ ISNULL(Postcode,'') )like '%'+@SearchText+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", postcode);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(dr["CompleteAddress"].ToString());
}
return result;
}
}
}
}
}
Please anyone can guide me.
Thanks