Set One Time DataSource for SearchBox

3 posts, 0 answers
  1. Venkata
    Venkata avatar
    128 posts
    Member since:
    Nov 2009

    Posted 27 May 2015 Link to this post

    Is is possible to set SearchBox Datasource only one time(when page is not postback)?

    Because i have to populate 10,000 Names in SearchBox each time if my page get post back

    here is my code

    protected void Page_Load(object sender, EventArgs e)

                radSearchEmployeeName.DataSource = GetEmployeeNameList();
                radSearchEmployeeName.DataTextField = "LeadFullName";
                radSearchEmployeeName.DataValueField = "LeadID";


    I am getting  "DataSource not set" error for below code

    if (!IsPostBack)

               radSearchEmployeeName.DataSource = GetEmployeeNameList();
                radSearchEmployeeName.DataTextField = "LeadFullName";
                radSearchEmployeeName.DataValueField = "LeadID";




  2. Hristo Valyavicharski
    Hristo Valyavicharski avatar
    975 posts

    Posted 29 May 2015 Link to this post

    Hi Venkata,

    It is a bad idea to load all 10 000 names on inital load. Better filter names on the server and return only those names that match the first letters. All SearchBox demos uses such approach:

    RadSearchBox Demos

    Hristo Valyavicharski
    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. BiBongNet
    BiBongNet avatar
    27 posts
    Member since:
    May 2010

    Posted 19 Jul 2015 in reply to Venkata Link to this post

    Hi Venkata,

    I think Hristo Valyavicharski's suggestion is the right direction.
    Recently, I have implemented SearchBox with the following way, and it is working very well so far. I'am posting it here for your reference.

    First, you should set DataSource for SearchBox with an empty list of objects inside Page_Load or Page_Init event, such as:

    //This is just an empty list
    radSearchEmployeeName.DataSource = new List<EmployeeName>();

    This is just to prevent SearchBox from showing "DataSource not sets" error popup when its DataSource is not set. No need to call DataBind() here. This means that the SearchBox is initially loaded with no data, hence good performance on load.

    Then, You can use DataSourceSelect event of SearchBox, and I would suggest you use a method to filter records from the database. I'am using full-text search. It would be something like this:


    private void SearchBox_DataSourceSelect(object sender, SearchBoxDataSourceSelectEventArgs e)
            //This is search string User types into Input of SearchBox
            var searchQuery = e.FilterString.Trim();


            //Use your search method here to filter records from the database
            //Should also set MaximumRows (or PageSize) as paging for better performance
            //And any other parameter as desired
            DataSource = YourFullTextSearchMethod(searchQuery [, startRowIndex, maximumRows]);

    If you use search on demand feature, I suggest you set a request delay to prevent SearchBox from sending request with every single character entered.

    This can be implemented by setting OnClientLoad event of SearchBox.


    And the Js function:

    function searchBox_ClientLoad(sender) {
        //This works with RadSearchBox, RadAutoCompleBox
        sender._requestDelay = 800;

    Hope this helps.

Back to Top