Click here to Skip to main content
15,888,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys,

I am currently implementing an autocomplete feature without using a webservice, and have put my ServiceMethod attribute in the autocomplete extender as GetProviders.

Here's how the GetProviders method looks like in the xxx.aspx.cs:
C#
public static string[] GetProviders(string prefixText, int count)
  {
      ArrayList fd = new ArrayList();
      fd.Add(DBManager.GetAllFood());
      return fd;
  }


Any idea how I can improve it??

Thanks in advance
Posted

1 solution

I use auto complete Extender just the way you do.. here take a look on code:

aspx page:

VB
<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
CompletionInterval="10" CompletionSetCount="10" DelimiterCharacters=""
Enabled="True" FirstRowSelected="true" MinimumPrefixLength="1"
ServiceMethod="GetName" TargetControlID="TextBox1" UseContextKey="true">


aspx.cs code:

[System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static List<string> GetName(string prefixText, int count)
    {
        if (count == 0) //count should not be zero
        {
            count = 5;
        }
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = <connectionstring>;
        SqlCommand cmd = new SqlCommand(sqlquery, conn);
        conn.Open();
        List<string> names = new List<string>();
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            names.Add(dr[<columnname>].ToString());
        }
        conn.Close();
        return names;
    }</columnname></connectionstring>


lemme know if it was what you were looking for.
 
Share this answer
 
Comments
Member 10915623 14-Aug-14 12:12pm    
Hey thanks, but I had implemented jquery autocomplete for now. I think this would do too, but Im curious what is the count really used for?
Thanks again!
Ashi0891 15-Aug-14 5:47am    
http://www.codeproject.com/Articles/259376/Using-AJAX-AutoCompleteExtender-for-autosuggest

it says "the “count” refers to the maximum number of records in the auto suggest" :)

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