Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 5th, 2012  |  syntax: None  |  size: 1.19 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to get the key value in jquery autocomplete when data coming from web service
  2. [WebMethod]
  3.     public List<string> AuotExtenderHotel(string hotelname)
  4.     {
  5.         DataSet ds = objHotelList.GetHotels(hotelname);
  6.         List<string> result = new List<string>();
  7.         foreach (DataRow dr in ds.Tables[0].Rows)
  8.         {
  9.             result.Add(dr["HotelName"].ToString());
  10.         }
  11.         return result;
  12.     }
  13.        
  14. <script type="text/javascript">
  15.     $(document).ready(function () { HotelText(); });
  16.     function HotelText() {
  17.         $(".txthotel").autocomplete({
  18.             source: function (request, response) {
  19.                 $.ajax({
  20.                     type: "POST",
  21.                     contentType: "application/json; charset=utf-8",
  22.                     url: "WebService.asmx/AuotExtenderHotel",
  23.                     data: "{'hotelname':'" + $('.txthotel').val() + "'}",
  24.                     dataType: "json",
  25.                     success: function (data) {
  26.  
  27.                         response(data.d);
  28.  
  29.  
  30.                     },
  31.                     error: function (result) {
  32.                         alert("Error");
  33.                     }
  34.  
  35.  
  36.                 });
  37.             }
  38.         });
  39.     }
  40. </script>