my auto complete is working fine as i can select the text . but problem is that i want to get the key value (Id) of selected item . so i can set on hidden field and use server side.
here is my web method code :
[WebMethod]
public List<string> AuotExtenderHotel(string hotelname)
{
DataSet ds = objHotelList.GetHotels(hotelname);
List<string> result = new List<string>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
result.Add(dr["HotelName"].ToString());
}
return result;
}
and here is my jquery autocomplete code
<script type="text/javascript">
$(document).ready(function () { HotelText(); });
function HotelText() {
$(".txthotel").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/AuotExtenderHotel",
data: "{'hotelname':'" + $('.txthotel').val() + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
How can you expect Id of the item in view if your server is not returning anything other than array of strings? I would modify the web method to return a JSON object which includes objects of ID and value pair. like
[{ "id": "1", "label": "MyFirstHotel", "value": "MyFirstHotel" },{ "id": "2", "label": "MySecondHotel", "value": "MySecondHotel" }]