now, i have to set the text of the combobox in code-behind (preselect)
radcombobox.text = "Basketball"
How can i call now the itemsrequest methode correct, with the argument of the
RadComboBoxItemsRequestedEventArgs ?
protected void ddlSport_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs
3 Answers, 1 is accepted
Why don't you move the loading Items logic from the ItemsRequested event handler into a separate routine with only one argument: the text that is being searched for? In this way, you can call this routine whenever necessary, or as in your case when you set the Text of the ComboBox.
Consider the following code:
| protected void Page_Load(object sender, EventArgs e) |
| { |
| RadComboBox1.Text = "Basketball"; |
| LoadItems(RadComboBox1.Text); |
| } |
| private void LoadItems(string text) |
| { |
| //Load Items... |
| } |
| protected void RadComboBox1_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) |
| { |
| LoadItems(e.Text); |
| } |
Best wishes,
Simon
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
this is a good idea, which i have also thought about. but how should i set the value for:
LoadItems(RadComboBox1.Text);
e.Message or e.EndOfItems = true; ???
DataTable data = DBManager.getInstance().getSportNames(e.Text);
try
{
int itemsPerRequest = 15;
int itemOffset = e.NumberOfItems;
int endOffset = itemOffset + itemsPerRequest;
if (endOffset > data.Rows.Count)
{
endOffset = data.Rows.Count;
}
if (endOffset == data.Rows.Count)
{
e.EndOfItems =
true;
}
else
{
e.EndOfItems =
false;
}
for (int i = itemOffset; i < endOffset; i++)
{
ddlSport.Items.Add(
new RadComboBoxItem(data.Rows[i]["Name"].ToString(), data.Rows[i]["SportsID"].ToString()));
}
if (data.Rows.Count > 0)
{
e.Message =
String.Format("Sportarten <b>1</b>-<b>{0}</b> von <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString());
}
else
{
e.Message =
"Keine Eintr„ge gefunden";
}
}
catch
{
e.Message =
"Keine Eintr„ge gefunden";
}
In this case you could change the approach a little bit:
| protected void Page_Load(object sender, EventArgs e) |
| { |
| RadComboBox1.Text = "Basketball"; |
| RadComboBox1.DataSource = GetItems("Basketball"); |
| RadComboBox1.DataBind(); |
| } |
| private DataTable GetItems(string text) |
| { |
| return DBManager.getInstance().getSportNames(e.Text); |
| } |
| protected void RadComboBox1_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) |
| { |
| DataTable data = LoadItems(e.Text); |
| //... |
| } |
Moreover, you could bind the ComboBox in Page_Load only to the first N results, similarly as in the ItemsRequested event handler, depending on your requirements.
Greetings,
Simon
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center