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

Autocompletebox sources

2 Answers 34 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Thibault
Top achievements
Rank 1
Thibault asked on 20 Nov 2015, 01:30 PM

Hi,

 I use Autocompletebox in my asp.net 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 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 25 Nov 2015, 09:13 AM
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:

http://docs.telerik.com/devtools/aspnet-ajax/controls/autocompletebox/server-side-programming/events/ondatasourceselect


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.

Regards,
Nencho
Telerik
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
0
Thibault
Top achievements
Rank 1
answered on 30 Nov 2015, 09:08 AM

Hello

 

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

 

Regards, 

Tags
AutoCompleteBox
Asked by
Thibault
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Thibault
Top achievements
Rank 1
Share this question
or