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

Load data in combo when it is clicked

3 Answers 55 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Thierry
Top achievements
Rank 1
Thierry asked on 23 Aug 2016, 01:54 PM

I have combo added to every cell header of my grid to provide row filtering but I'm trying to load the data in the combo when it is clicked as per your sample:

http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/comboboxvsdropdownlist/defaultcs.aspx?skin=Sunset

but no data is requested as per your sample. If I type something in the combo, it does trigger the ItemsRequested event, but I would like to load data when the combo is clicked. The reason I don't want to preloaded (as it is currently done!) is that if a user never uses any of the filters, he/she should not have to be penalized having to wait additional time for these to be filled, queries to get this data should not be executed, etc...

This is the code I'm currently using:

RadComboBox comboBox = new RadComboBox();
comboBox.ID = GetFilterID(columnIndex);
comboBox.MarkFirstMatch = true;
comboBox.AutoPostBack = true;
comboBox.CssClass = "Filter";
comboBox.TextChanged += new EventHandler(comboBox_TextChanged);
comboBox.ShowDropDownOnTextboxClick = true;
comboBox.AppendDataBoundItems = true;
comboBox.EnableLoadOnDemand = true;
comboBox.DataTextField = filterableField.DataField;
comboBox.DataValueField = filterableField.DataField;
//comboBox.DataSource = GetFilterData(filterableField.DataField);
comboBox.ItemsRequested +=new RadComboBoxItemsRequestedEventHandler(comboBox_ItemsRequested);
comboBox.EnableVirtualScrolling = false;
comboBox.ShowMoreResultsBox = false;
comboBox.AllowCustomText = false;

headerCell.Controls.Add(comboBox);

private void comboBox_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    Debug.WriteLine("");  //Load additional data from here.
}

There is no html code as this is all done at run-time. Based on your sample as per link above, I can't spot any difference except that you have a RenderMode to "LightWeight" but I don't think that's the problem.

Any ideas?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Thierry
Top achievements
Rank 1
answered on 25 Aug 2016, 02:03 PM

I'll add a bit of feedback but my issue is still not sorted.

When trying to reproduce the problem in a new (empty) project, I noticed a couple of things:

1. When defining the RadComboBox directly in my aspx page, it worked immediately.

2. When creating the RadComboBox via code, it didn't work. My colleague then suggested that instead of adding the control to the page i.e. Page.Control.Add(combo), that I add it instead to a Panel. This solved the problem in test website but it still not displaying any of the requested data for some reason, even though the source is binded in the ItemsRequested and my code is identical as the one used in point 1. which displays everything correctly.

I thought this could be the problem in my main app, but my RadComboBox is not added to the page directly. It is added to a TableCell which belongs to RadGrid but to be sure, I added the combo to a panel and then added the panel to my TableCell but it made no difference! It still doesn't trigger the ItemsRequested event.

The Telerik version I'm using is: 2010.2.713.35, if that's of any use.

Could it be a bug?

 

it behaved exactly as my original question did i.e. ItemsRequested is not triggered when clicking on the drop down button.

0
Thierry
Top achievements
Rank 1
answered on 25 Aug 2016, 03:55 PM

I've given up trying to figure out why it's not working! Spent far too much time on it as it is!

I've found a work-around and while I personally think it's ugly, it does work and it appears to be reliable. I'm now capturing on the client side when the drop down is expanded and when it is I'm calling the '.itemsRequested' via JavaScript. This seems to be reliable though I'm having a couple of minor issues where the number of items in my list always appears to be 1 when it should be 0 and my drop down is flickering a bit when my data is loaded but that could just be that I need to set a bigger height or something like similar.

Anyway, here's the code I used my comboBox_PreRender:

RadComboBox comboBox = (RadComboBox)sender;
RadScriptManager.RegisterClientScriptBlock(comboBox.NamingContainer,
comboBox.NamingContainer.GetType(),
"ComboBoxDropDownOpening",
@"
function ComboBoxDropDownOpening(sender, args)
{
//alert('ComboBoxDropDownOpening - There are now ' + sender.get_items().get_count() + ' items.');
if (sender.get_items().get_count() === 1)
{
sender.requestItems();
}
}
",
true);

You may have to tweak it a bit, but hopefully this will help.

 

0
Peter Milchev
Telerik team
answered on 26 Aug 2016, 11:28 AM
Hello Thierry,

We recommend upgrading to the latest version of our controls. This way you could benefit not only from the bug fixes but the improved functionality and new features and controls.

If updating to the latest version of the control does not solve the issue, would you please open an official support ticket with attached a sample runnable project that implements your approach and reproduces the problem?Thus, we would be able to investigate locally and help you in the most efficient way.

Regards,
Peter Milchev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
ComboBox
Asked by
Thierry
Top achievements
Rank 1
Answers by
Thierry
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or