Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using entity framework in my application in that i autocomplete textbox using linq . In debug mode it retrive value but in page city name not display.Am i doing something wrong?

XML
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetSuggessions(string prefixText, int count, string contextKey)
{
  
     List<string> res = MasterDTO.GetCities(21).Select(s => s.CityName).ToList();
    List<string> suggestions = res
  .Where(a => a.StartsWith(prefixText))
  .Take(count)
  .ToList();
    // contextKey can be used to set further filter
    return suggestions;
}


XML
<asp:ScriptManager ID="ScriptManager2" EnablePageMethods ="true" runat="server" />

   <asp:TextBox ID="txtAutoComplete" runat="server"  ></asp:TextBox>
       <ajax:AutoCompleteExtender   ID="AutoCompleteExtender1"    runat="server" TargetControlID="txtAutoComplete"  runat="server"  MinimumPrefixLength="1"
       EnableCaching="true"
       CompletionInterval="100"
       ServiceMethod="GetSuggessions"
       CompletionSetCount="20"
       ContextKey="strOtherPram">
       </ajax:AutoCompleteExtender>
Posted

1 solution

Hi,

try like below.
C#
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetSuggessions(string prefixText, int count, string contextKey)
{
  
    List<string> res = MasterDTO.GetCities(21).Select(s => s.CityName).ToList();
    string[] suggestions = res.Where(a => a.StartsWith(prefixText)).ToList().ToArray();
    // contextKey can be used to set further filter
    return suggestions;
}


because, the web method signature, should be like below.
C#
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetSuggessions(
    string prefixText, int count, string contextKey) { ... }

the function should return string array.

refer AutoComplete Demonstration[^] for more
 
Share this answer
 
v3
Comments
Manohar Khillare 2-Apr-13 2:28am    
Again its not working
Karthik Harve 2-Apr-13 2:52am    
try with updated solution.
Manohar Khillare 2-Apr-13 3:02am    
I TRY IT BUT IT NOT DISPLAY VALUE

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