Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
[OperationContract]
       [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
       public object  GetStationList(string prefixText)
       {

           using (DatabaseScope dbScope = new DatabaseScope("XTPTenant"))
           {
               dbScope.Database.ConnectionString = System.Web.HttpContext.Current.Session["ConnectionString"].ToString();
               ILocationCriteria locationCriteria = wcfFactory.CreateObject<ILocationCriteria>();
               locationCriteria.TrainStationName = prefixText;
               List<ITrainStation> StationList = XTP.Business.ProductSearch.SearchTrainStations(locationCriteria);
               object[] resarr = new object[1];
               if (StationList != null && StationList.Count > 0)
               {
                   object[] namearr = new object[StationList.Count];
                   for (int i = 0; i < StationList.Count; i++)
                   {
                       namearr[i] = StationList[i].Name;//+ ", " + StationList[i].Code;
                       namearr[i] = namearr[i] + "<div style=display:none>" + BitSpark.EnumHelper.GetDescription(XTP.Data.General.StringSeparator)
                           + StationList[i].Name + BitSpark.EnumHelper.GetDescription(XTP.Data.General.StringSeparator)
                           + StationList[i].ID  + BitSpark.EnumHelper.GetDescription(XTP.Data.General.StringSeparator) + "</div>";
                   }
                   resarr[0] = namearr;
               }
               else
               {
                   object[] errarr = new object[1];
                   errarr[0] = "No matching Station found";
                   resarr[0] = errarr;
               }
              return resarr;
             //  return StationList;
               //}
           }
       }
Posted
Updated 29-Jul-11 15:24pm
v2
Comments
Member 8043227 29-Jul-11 18:39pm    
$(function () {
$("#<%=txtTrainNumber.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
url: "../MetaService.svc/GetStationList",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: '{"prefixText":"' + request.term + '"}',
error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); },
success: function (data) {
alert(data.d);
response($.map(data.d, function (item) {
alert(item);
return {
style: "full",

label: item.Name,
value: item.Name,
station: item

}
}))
}
})
},
minLength: 1,
select: function (event, ui) {
$("#<%=SelectedSupplierHiddenField.ClientID %>").val(ui.item.station.ID);
},
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
$("#<%=SelectedSupplierHiddenField.ClientID %>").val('');
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
$("#<%=SelectedSupplierHiddenField.ClientID %>").val('');
}
});

});
Member 8043227 29-Jul-11 18:41pm    
i am trying to display auotocomplete list of stations in a text box. Function is returning correct values,, but list of stations comes up blank with single row..
ZurdoDev 15-Mar-12 11:00am    
Just put a breakpoint and debug it. You are likely accessing the controls wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900