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

Set One Time DataSource for SearchBox

2 Answers 39 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
Venkata
Top achievements
Rank 1
Venkata asked on 27 May 2015, 09:21 PM

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";
            radSearchEmployeeName.DataBind();

}

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

if (!IsPostBack)
 {

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

}

 

 

2 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 29 May 2015, 06:40 AM
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

Regards,
Hristo Valyavicharski
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
BiBongNet
Top achievements
Rank 2
answered on 19 Jul 2015, 07:45 PM

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.

OnClientLoad="searchBox_ClientLoad"

And the Js function:

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


http://www.telerik.com/forums/webservicesettings-delay-issue-handling-of-requests-in-order


Hope this helps.
BBN.

Tags
SearchBox
Asked by
Venkata
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
BiBongNet
Top achievements
Rank 2
Share this question
or