Autocompletebox sources

3 posts, 0 answers
  1. Thibault
    Thibault avatar
    2 posts
    Member since:
    Nov 2015

    Posted 20 Nov 2015 Link to this post


     I use Autocompletebox in my website for load postal code from by sql servr's database. But it take a lot of time (15 second.. to long). And It seem that, if I understand, autocomplete box load ALL my postal code from database and after that, use the string research...

    My question is here, did it is possible to call a function sql server with, on parameter, the text witch is written in the Autocompletebox

    I've tried a code like : 

            protected void RadAutoCompleteBox1_TextChanged(object sender, AutoCompleteTextEventArgs e)
                string recherche = RadAutoCompleteBox1.Text;
                SqlDataSource2.SelectCommand = "select CodePostal,NomCommune from GetVilleByCpTelerik2(" + recherche + ") order by CodePostal OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY";


    But it doesn't work. I have error message like "The object reference is not definied"


    Can I have help please ?


    Ps : Sorry for my English level

  2. Nencho
    Nencho avatar
    1661 posts

    Posted 25 Nov 2015 Link to this post

    Hello Thibault,

    Actually the RadAutoCompleteBox works a bit differently. The control works upon callbacks, in order to request its underlying (associated) data source. In other words, once the end user types/deletes a character in the input of the control - the AutoCompleteBox triggers a callback, in order to acquire the result set, base on present text in the input.

    There might be several reasons for the experienced issue:
      1. Slow/problematic connection with your database.
      2. Enormous amount of data, that needs to be searched for the corresponding results in the database.
      3. If the underlying data is enormous - the returned results also will be a lot, which would need additional time to render the results on the page.

    However, regarding the your question - you can use the OnDataSourceSelect serve-side event of the control, which is triggered, just before the result items are requested from the underlying DataSource. At the handler of the event, you can build a custom query, in order to obtain a preferable set of results. For example you can get the first 100 results, regarding the text of the input in the control. Please refer to the following documentation article, providing more information on the usage of the event:

    On a side note, I would like to ask you to submit your inquiries for our product in the corresponding forums. In other words, please make sure that you have set the correct Product for the ticket/forum that you are about to submit.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Thibault
    Thibault avatar
    2 posts
    Member since:
    Nov 2015

    Posted 30 Nov 2015 in reply to Nencho Link to this post



    Thank you for this answer, I'll try this as soon as possible



Back to Top