in my below code autocomplete is working but name and city both textboxes showing the mix result of name and city. name should display only names and city should display only cities name. i am new to AJAX .
.aspx code
<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: "demoSearch.aspx/GetAutoCompleteData",
data: "{'username':'" + document.getElementById('txtName').value + "','City':'" + document.getElementById('txtCity').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
----
<div class="ui-widget">
<label for="tbAuto">
Enter UserName:
</label>
<input type="text" id="txtName" class="autosuggest" />
<label for="tbAuto">
Enter city:
</label>
<input type="text" id="txtCity" class="autosuggest" />
</div>
.aspx.cs
public static List<string> GetAutoCompleteData(string username,string City)
{
List<string> result = new List<string>();
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
using (SqlCommand cmd = new SqlCommand("select UserName,City from userRegistrationTB where UserName LIKE '%'+@txtName+'%' OR City Like '%'+@txtCity+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", username);
cmd.Parameters.AddWithValue("@txtCity",City);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(dr["UserName"].ToString());
result.Add(dr["City"].ToString());
}
return result;
}
}