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

Autocomplete Bind to DataTable

1 Answer 119 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 17 Oct 2013, 10:33 PM
I have a stored procedure that get a list of categories from my database
Select Category from Categories
I then have some code that execute the stored procedure and returns the data to a datatable
Public Shared Function GetDescription() As DataTable
            Dim comm As DbCommand = GenericDataAccess.CreateCommand()
            comm.CommandText = "GetDescriptions"
 
            Return GenericDataAccess.ExecuteSelectCommand(comm)
        End Function
I then call this method to bind to the auto complete box
Protected Sub txtSearch_DataBinding(sender As Object, e As EventArgs) Handles txtSearch.DataBinding
 
       txtSearch.DataSource = GetMethods.GetDescription()
 
   End Sub
then call the databind on page load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       If Not IsPostBack Then
           txtSearch.DataBind()
       End If
   End Sub
This is my front end code for the autocomplete
<telerik:RadAutoCompleteBox ID="txtSearch" DataTextField="Category" DataValueField="Category" runat="server" EmptyMessage="Please enter search term"></telerik:RadAutoCompleteBox>
when I run the page and start typing i get the attached error message.  Have I missed something really simple here?

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 22 Oct 2013, 07:56 AM
Hi Simon,

RadAutoCompleteBox is designed in such a way that it doesn't store a collection of items on the server, inflating the ViewState. Instead it uses lazy loading. When it's loaded initially, it doesn't request anything from it's datasource. When you start typing, a callback is triggered and only then the datasource is hit, collecting the results. So the datasource has to be available on each postback. 

The following help article demonstrates the proper way to bind the AutoCompleteBox to a DataTable:
http://www.telerik.com/help/aspnet-ajax/autocompletebox-databinding-datatable-set-view.html

 

Regards,
Bozhidar
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
AutoCompleteBox
Asked by
Simon
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or