Click here to Skip to main content
11,714,345 members (83,261 online)
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 19: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 Sergey Alexandrovich Kryukov 540
1 Maciej Los 259
2 Richard MacCutchan 230
3 OriginalGriff 140
4 F-ES Sitecore 140
0 Sergey Alexandrovich Kryukov 545
1 CHill60 375
2 Maciej Los 324
3 Richard MacCutchan 310
4 OriginalGriff 260


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2015
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