Can't get autocomplete to work with large data set

2 posts, 0 answers
  1. Christopher
    Christopher avatar
    17 posts
    Member since:
    Feb 2008

    Posted 21 Sep 2011 Link to this post

    Greetings,

    I was able to get the RadComboBox to work with autocomplete by loading all of the distinct rows from my sql datatable for a certain column and returning them all at once. Naturally with a lot of values it was very slow, but none the less it worked. Knowing this wouldnt be ok for production I began digging into the LoadOnDemand demo's, specifically this one:
    http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultcs.aspx

    I used the demo almost verbatim in my code as I want it to work like the server side example. However when I click my combobox it shows the first 10 items (or whatever I set it to) but when I start typing in lettters it goes to "Loading.." and unless the value is in that first set of 10 it won't autocomplete. Basically it has to be in the ItemsRequested set in order to autocomplete. Is it possible to autocomplete with large data sets without having to load every item into the combobox?

    (sorry for the long post, I figured more detail is better than less). Any help is appreciated.

    btw FillComboBox() just returns my query string..

    My Control:
    <telerik:RadComboBox ID="ddlRadComboBox" Runat="server"
                EmptyMessage="Enter a skill name" 
                    MarkFirstMatch="True"
                    MaxLength="200" ShowDropDownOnTextboxClick="True" 
                    OnItemsRequested="ddlRadComboBox_ItemsRequested" 
                    EnableVirtualScrolling="True" ItemsPerRequest="10"
                    ShowMoreResultsBox="true" EnableLoadOnDemand="True"
                     />

    private DataTable GetData(string text)
            {
                try
                {
                    //using() requires no close()
                    using (connection = new SqlConnection(ConnectionString))
                    {
                        //open connection to db
                        connection.Open();
      
                        //change command query based on dropdown
                        myCommand = new SqlCommand(FillComboBox(), connection);
                        using (adapter = new SqlDataAdapter(myCommand))
                        {
                            comboBoxDT = new DataTable();
                            adapter.Fill(comboBoxDT);
      
                            return comboBoxDT;
                        }
                    }
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
      
                return comboBoxDT;
            }

    protected void ddlRadComboBox_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        DataTable data = GetData(e.Text);
        int itemOffset = e.NumberOfItems;
        int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);
        e.EndOfItems = endOffset == data.Rows.Count;
        for (int i = itemOffset; i < endOffset; i++)
        {
            ddlRadComboBox.Items.Add(new RadComboBoxItem(data.Rows[i]["SkillName"].ToString(), data.Rows[i]["SkillName"].ToString()));
        }
    }
  2. Christopher
    Christopher avatar
    17 posts
    Member since:
    Feb 2008

    Posted 21 Sep 2011 Link to this post

    Okay I got it working using the auto LoadOnDemand! Feel free to get rid of this thread if its taking up room, sorry!
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top