This is a migrated thread and some comments may be shown as answers.

Can't get autocomplete to work with large data set

1 Answer 175 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Christopher
Top achievements
Rank 1
Christopher asked on 21 Sep 2011, 09:08 PM
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()));
    }
}

1 Answer, 1 is accepted

Sort by
0
Christopher
Top achievements
Rank 1
answered on 21 Sep 2011, 09:55 PM
Okay I got it working using the auto LoadOnDemand! Feel free to get rid of this thread if its taking up room, sorry!
Tags
ComboBox
Asked by
Christopher
Top achievements
Rank 1
Answers by
Christopher
Top achievements
Rank 1
Share this question
or