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

Cascading combo-box not functioning properly

1 Answer 85 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Xorv
Top achievements
Rank 2
Xorv asked on 08 May 2012, 09:18 AM

I've two combo-box(Countries and States). Combo-box 2 (States) should load associated States with the value selected in the Combo-box 1(Countries).

Problem:- first time selection of a Countries combo-box item, loads the correct associated States in the 2nd combo-box. But when an another value is selected in combo-box 1. The Values inside combo-box still displays old values.

NOTE:- On 2nd time NewValues are loaded properly in combo-box 2. But those are not displayed when the the combo-box arrow is click (Only old values are visible). But if we type anything in that 2nd combo-box, New values are displayed.

QUESTION:- I want evertime the new values are loaded up in 2nd combo-box, it should be displayed on the click of combo-box arrow. Not just after typing something.

CLASS:-

protected void Countries_SelectedIndexChanged(Object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
    int countryIDselected = Convert.ToInt32(Countries.SelectedValue);
    bool AdvanceSearchFlag = true;
    Session["AdvanceSearchFlag"] = AdvanceSearchFlag;
    Session["countryIDselected"] = countryIDselected.ToString();
  
    int totalStates = States.Items.Count;
    int xyz = totalStates - 1;        if (totalStates != 0)
    {
        while (totalStates > 0)
        {
            States.Items.Remove(totalStates - 1);
            totalStates --;
        }
    }
    States.Items.Clear();
}
  
protected void States_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
    foreach (StateyLookupInfo state in StateLookupList.GetList(false))
    {
        RadComboBoxItem item = new RadComboBoxItem(State.StateName, State.StateID.ToString());
        comboBox.Items.Add(item);
    }
}

ASPX:-
<telerik:RadComboBox ID="Countries" runat="server" AutoPostBack="True" OnSelectedIndexChanged="Countries_SelectedIndexChanged" />
<telerik:RadComboBox ID="States" runat="server" AutoPostBack="True" EnableLoadOnDemand="true" OnItemsRequested="States_ItemsRequested" />

1 Answer, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 10 May 2012, 01:53 PM
Hello,

In order to force a request for items whenever the second RadComboBox is opened, the OnClientDropDownOpening event should be handled with the following implementation of the event handler function:
function OnClientDropDownOpening(sender, args) {
 
      if (sender.get_items().get_count() > 0)
          sender.requestItems("", false);
  }

Greetings,
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.
Tags
ComboBox
Asked by
Xorv
Top achievements
Rank 2
Answers by
Dimitar Terziev
Telerik team
Share this question
or