Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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?
 
[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;
}
 
<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-Apr-13 20:55pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
try like below.
[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.
[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
  Permalink  
v3
Comments
Manohar Khillare at 2-Apr-13 2:28am
   
Again its not working
Karthik Harve at 2-Apr-13 2:52am
   
try with updated solution.
Manohar Khillare at 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)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100