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

Any way to selectively filter on client side?

7 Answers 169 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 15 Nov 2011, 10:04 PM
I'm not even sure this can be done, but here goes:

What I am trying to do is avoid database hits on every character entered in a Load-On-Demand RadComboBox.  When one character is entered, I go to the database and get the resulting dataset.  Any further characters entered will filter that same dataset.  The only time the database is accessed is when the first character is entered.  Is this even possible? If so, any pointers?

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Nov 2011, 08:07 AM
Hello,

You can try the following code snippet.
C#:
protected void RadComboBox5_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
  if (e.Text.Length <=1)
   {
    GetDataItem(e.Text);
    RadComboBox5.DataSource = dt;
    RadComboBox5.DataTextField = "FirstName";
    RadComboBox5.DataValueField = "EmployeeID";
    RadComboBox5.DataBind();
   }
  else
   {
     DataTable temp = new DataTable();
     temp=(DataTable) Session["DtTemp"];
     string exp="FirstName like '"+e.Text+"' + '%'";
     DataTable dt1 = new DataTable();
     dt1.Columns.Add("EmployeeID", typeof(int));
     dt1.Columns.Add("FirstName", typeof(string));
     DataRow[] dr1 = temp.Select(exp);
     foreach (DataRow dRow in dr1)
     {
      DataRow dr = dt1.NewRow();
      dr["EmployeeID"] = dRow["EmployeeID"];
      dr["FirstName"] = dRow["FirstName"];
      dt1.Rows.Add(dr);
     }
     RadComboBox5.DataSource = dt1;
     RadComboBox5.DataTextField = "FirstName";
     RadComboBox5.DataValueField = "EmployeeID";
     RadComboBox5.DataBind();
   }
}
protected void GetDataItem(string text)
{
  String s = "select FirstName,EmployeeID from Employees WHERE FirstName like @text + '%'";
  con.Open();
  SqlDataAdapter dr = new SqlDataAdapter(s, con);
  dr.SelectCommand.Parameters.AddWithValue("@text", text);
  dt = new DataTable();
  dr.Fill(dt);
  Session["DtTemp"] = dt;
  con.Close();
}

Thanks,
Princy.
0
Steve
Top achievements
Rank 1
answered on 17 Nov 2011, 02:55 PM
Thanks Princy.   So the key is to use a local table?  Is there any way to avoid that?
0
Dimitar Terziev
Telerik team
answered on 22 Nov 2011, 11:05 AM
Hi Steve,

Another approach is to subscribe on the client-side OnClientItemsRequesting event and cancel it if there are items in the RadComboBox. In such case the server-side ItemsRequested event won't be fired as well and therefore no call to be data base will be made.

All the best,
Dimitar Terziev
the Telerik team
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 their blog feed now
0
Steve
Top achievements
Rank 1
answered on 22 Nov 2011, 01:44 PM
Dimitar, do you have a sample for this?  I've tried this approach but the data doesn't persist in the combo box.
0
Dimitar Terziev
Telerik team
answered on 25 Nov 2011, 12:20 PM
Hi Steve,

Please find attached a sample page as requested.

Hope this would help you out.

Regards,
Dimitar Terziev
the Telerik team
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 their blog feed now
0
Steve
Top achievements
Rank 1
answered on 28 Nov 2011, 03:51 PM
Thanks for the sample, but it's not working for me.  I basically tried the same thing, but it doesn't filter anything after the first character.  For example, if I have two names beginning with S - Smith and Samuels.  Both names show up in the list when I enter 'S', and both names stay in the list no matter what I enter after that.
0
Ivana
Telerik team
answered on 01 Dec 2011, 01:04 PM
Hi Steve,

I have prepared a sample web page which shows the scenario in question using Princy's approach, where the RadComboBox withdraws data from a database instead of a DataTable.

The RadComboBox withdraws data from the database only once, on drop-down opening, and saves the data in a Session. Therefore, when the user types text in the input field, the RadComboBox gets filled with the data stored in the Session, without making a call to the database on every letter typed.

You could take a look at the attached sample, and give it a try locally.

I hope this helps.

All the best,
Ivana
the Telerik team
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 their blog feed now
Tags
ComboBox
Asked by
Steve
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Steve
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Ivana
Telerik team
Share this question
or