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

cascading dropdowns

3 Answers 84 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
MBEN
Top achievements
Rank 2
Veteran
MBEN asked on 21 Nov 2011, 08:49 PM
Hi.

I have two dropdowns in the edit form of a grid which are populated using an objectdatasource.
I have a radupload control in the grid as well.

My second combo is dependent on the selectyion in the first combo and in the selectedindexchanged event i was putting the value in a session variable and the object datasource for the second combo was using the session parameter.

The issue I had was that the validation on the radupload was getting fired on the postback and the code never reached the delectedindexchanged event. I want to disable the autopostback property of the first combo and somehow populate the second combo using javascript so that the validation event for the radupload fires at the correct time.

I am having trouble populating the second combo using javascript. I populated a hidden variable with the sleected value and did a requestItems() for secondcombo in the clientselectedindexchanged event but that does not help.

Please help.

3 Answers, 1 is accepted

Sort by
0
MBEN
Top achievements
Rank 2
Veteran
answered on 23 Nov 2011, 12:09 AM
I am stuck on this one.
Please any help is appreciated.
0
Ivana
Telerik team
answered on 24 Nov 2011, 11:50 AM
Hi Mben,

This is a rather unusual behavior. What kind of a validator is used for the RadUpload, and also, what happens when that validator is removed? Does the SelectedIndexChanged event of the RadComboBox gets fired?

Furthermore, in such a scenario, it is better to use the LoadOnDemand (initiated by the requestItems method ) approach; used for a related RadComboBoxes' population. The following online demo: Related ComboBoxes, shows how such scenario could be achieved. You could take a look at its implementation.

Also, here is a simple example showing the above mentioned scenario:
var secondCombo;
 
function pageLoad()
{
    var firstCombo = $find("<%= RadComboBox1.ClientID %>");
    secondCombo = $find("<%= RadComboBox2.ClientID %>");
      //first pageLoad population of the second combo          
    if (firstCombo.get_selectedItem() != null)
    {
        secondCombo.requestItems(firstCombo.get_selectedItem().get_text(), false);
    }
}
 
function selectedIndexChanged(sender, args)
{
    secondCombo.requestItems(args.get_item().get_text(), false);
}
<telerik:RadComboBox runat="server" ID="RadComboBox1" OnClientSelectedIndexChanged="selectedIndexChanged">
    <Items>
        <telerik:RadComboBoxItem Value="item1" Text="item1" />
        <telerik:RadComboBoxItem Value="item2" Text="item2" />
        <telerik:RadComboBoxItem Value="item3" Text="item3" />
    </Items>
</telerik:RadComboBox>
<telerik:RadComboBox runat="server" ID="RadComboBox2" OnItemsRequested="RadComboBox2_ItemsRequested">
</telerik:RadComboBox>
protected void RadComboBox2_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    RadComboBoxItem item = new RadComboBoxItem();
 
    if (e.Text == "item1")
    {
        item.Text = "item1_newItem";
        item.Value = "item1_newItem";
        RadComboBox2.Items.Add(item);
    }
    if (e.Text == "item2")
    {
        item.Text = "item2_newItem";
        item.Value = "item2_newItem";
        RadComboBox2.Items.Add(item);
    }
    if (e.Text == "item3")
    {
        item.Text = "item3_newItem";
        item.Value = "item3_newItem";
        RadComboBox2.Items.Add(item);
    }
}

Best wishes,
Ivana
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
0
MBEN
Top achievements
Rank 2
Veteran
answered on 24 Nov 2011, 09:06 PM
I was using a custom validator. When the validator was removed the selectedindexchanged event was being fired.
However, the solution you gave worked for me.

Thanks for the help.
Tags
ComboBox
Asked by
MBEN
Top achievements
Rank 2
Veteran
Answers by
MBEN
Top achievements
Rank 2
Veteran
Ivana
Telerik team
Share this question
or