Autocomplete Bind to DataTable

2 posts, 0 answers
  1. Simon
    Simon avatar
    3 posts
    Member since:
    Dec 2012

    Posted 17 Oct 2013 Link to this post

    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
           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?
  2. Bozhidar
    Bozhidar avatar
    1096 posts

    Posted 22 Oct 2013 Link to this post

    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:


    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top