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

How to set selected value after load on demand

1 Answer 124 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
James Daresta
Top achievements
Rank 1
James Daresta asked on 11 Oct 2013, 08:15 PM

I have a combo with load on demand and I refresh via javascript. What I want is the combo to populate items and then go and selected item that matches a value id. So for example:

  OlinCA.loadStates = function (country, selectedState) {
    var rcbContactState = $find("<%= rcbContactState.ClientID %>");
    rcbContactState.set_text("Loading...");
    rcbContactState.clearSelection();
    rcbContactState.requestItems((country + '~' + selectedState), false);
    rcbContactState.findItemByValue(selectedState).select();
}


As you see I am passing a value to populate the combo by a selected country and then select a matching state. Well every time I call that findItemByValue I get an error because that line fires before the list is populated. I need somehow to have the load request finish first. I tried to select a value via the server side code, but nothing gets selected. What is the way I can do the selection like I need to?



1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 16 Oct 2013, 03:58 PM
Hi James,

The RadComboBox makes requests and this may take little longer time. That's why you may handle OnClientItemsRequested event, which you be fired immediately after the combo loads the filtered items and then call findItemByValue(). Something similar to this:

function OnClientItemsRequested(sender, args) {
sender.findItemByValue(selectedState).select();
}

Regards,
Hristo Valyavicharski
Telerik
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 the blog feed now.
Tags
ComboBox
Asked by
James Daresta
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or