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

SearchBox Error

3 Answers 74 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 23 May 2014, 03:47 PM
I'm programmatically binding data to a RadSearchBox [I get my data list back from a Service Reference] and I set the DataTextField and DataValueField, then I set the DataSource - all without errors.  However, when I start typing in the search box, I receive a popup on the page: DataSource not set

What am I missing?
<telerik:RadSearchBox runat="server" ID="radTest" OnSearch="radTest_OnSearch"></telerik:RadSearchBox>

protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    UserServiceClient client = new UserServiceClient();
    var users = client.GetSecurityUsers().ToList();
    radTest.DataTextField = "full_name";
    radTest.DataValueField = "user_id";
    radTest.DataSource = users;
  }
}
protected void radTest_OnSearch(object sender, SearchBoxEventArgs e)
{
  UserServiceClient client = new UserServiceClient();
  var users = client.GetSecurityUsers().ToList();
  if (!string.IsNullOrEmpty(e.Text))
  {
    users = users.Where(i => i.full_name.Contains(e.Text)).ToList();
  }
  radTest.DataTextField = "full_name";
  radTest.DataValueField = "user_id";
  radTest.DataSource = users;
}



3 Answers, 1 is accepted

Sort by
0
Aneliya Petkova
Telerik team
answered on 27 May 2014, 09:28 AM
Hello Mike,

Please try to bind the data source on Page_Load:

protected void Page_Load(object sender, EventArgs e)
{
    BindToList(RadSearchBox1);
}
 
private void BindToList(RadSearchBox searchBox)
{
    UserServiceClient client = new UserServiceClient();
    var users = client.GetSecurityUsers().ToList();
    searchBox.DataTextField = "full_name";
    searchBox.DataValueField = "user_id";
    searchBox.DataSource = users;
}

If this doesn't help, please provide me with a very simplified runnable project, which I can inspect locally and advise you further.

You can also check the following article on how to bind to array or array list:
http://www.telerik.bg/help/aspnet-ajax/searchbox-databinding-array.html

Regards,
Aneliya Petkova
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mike
Top achievements
Rank 1
answered on 28 May 2014, 06:25 PM
I've got a test app (zipped) that has the error in it, where can I send the zip file to?
0
Aneliya Petkova
Telerik team
answered on 29 May 2014, 10:10 AM
Hello Mike,

File attachments are not supported in the Telerik Forum.
If you want to send us your project, you should start a new support ticket. Please include there the url of this forum thread. That will help us to track the problem easier.

Regards,
Aneliya Petkova
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
SearchBox
Asked by
Mike
Top achievements
Rank 1
Answers by
Aneliya Petkova
Telerik team
Mike
Top achievements
Rank 1
Share this question
or