Telerik RadComboBox supports the functionality to load data on demand based on the current value of the combobox input field. Whenever the state of the input changes, Telerik RadComboBox fires a server-side event (ItemsRequested) with the current state of the input as a parameter of the EventArgs.
Related properties:
ItemRequestTimeout - the timeout in milliseconds before the server event is executed.
Related client-events:
 |
Remark: If you need to get the text/value of the selected item on the server side, when the items are added via callback(in the ItemsRequested event handler), you need to use the following syntax (the SelectedItem and SelectedValue properties are null since the combobox items are added only on the client side): To get the text of the selected item - RadComboBox1.Text To get the value of the selected item - RadComboBox1.Value |
Consider the examples below:
Hooking the ItemsRequested event:
| ASPX |
Copy Code |
|
<radcb:RadComboBox runat="server" OnItemsRequested="RadComboBox1_ItemsRequested" /> |
| C# |
Copy Code |
|
this.RadComboBox1.ItemsRequested += new Telerik.WebControls.RadComboBoxItemsRequestedEventHandler (this.RadComboBox1_ItemsRequested); |
| VB.NET |
Copy Code |
|
AddHandler RadComboBox1.ItemsRequested, AddressOf Me.RadComboBox1_ItemsRequested
|
Sample implementation - fetches all words similar to the current word from a database. You just need to get a set of items and load them in the ComboBox instance.
| C# |
Copy Code |
|
private void RadComboBox1_ItemsRequested(object o, Telerik.WebControls.RadComboBoxItemsRequestedEventArgs e) { RadComboBox combo = (RadComboBox) o; combo.Items.Clear();
string mdbPath = Server.MapPath("Data/NWind.mdb"); OleDbConnection dbCon = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath); dbCon.Open();
string text = e.Text; string sql = "SELECT * from Customers WHERE CompanyName LIKE '" + text + "%'";
OleDbDataAdapter adapter = new OleDbDataAdapter(sql, dbCon); DataTable dt = new DataTable(); adapter.Fill(dt); dbCon.Close();
foreach (DataRow row in dt.Rows) { RadComboBoxItem item = new RadComboBoxItem(row["CompanyName"].ToString()); combo.Items.Add(item); } } |
| VB.NET |
Copy Code |
|
Private Sub RadComboBox1_ItemsRequested(ByVal o As Object, ByVal e As Telerik.WebControls.RadComboBoxItemsRequestedEventArgs) Dim combo As RadComboBox = CType(o,RadComboBox) combo.Items.Clear Dim mdbPath As String = Server.MapPath("Data/NWind.mdb") Dim dbCon As OleDbConnection = New OleDbConnection(("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath)) dbCon.Open Dim text As String = e.Text Dim sql As String = ("SELECT * from Customers WHERE CompanyName LIKE '" _ + (text + "%'")) Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(sql, dbCon) Dim dt As DataTable = New DataTable adapter.Fill(dt) dbCon.Close For Each row As DataRow In dt.Rows Dim item As RadComboBoxItem = New RadComboBoxItem(row("CompanyName").ToString) combo.Items.Add(item) Next End Sub
|
Please note that you need to use the ExternalCallBackPage property of Telerik RadCombobox to place the combobox inside a user control (an ASCX file). You can also use ExternalCallBackPage for complex load-on-demand scenarios, e.g. load-on-demand combobox inside an asp:datagrid EditTemplate.
See Also