Search code examples
asp.netvb.netrefreshcascadingdropdown

Prob with resetting CascadingDropBoxList :S


thanks for reading, this is a bit long, but I hope someone can help me!

I've got the following set up:

On a webapp, I've got an updatepanel

Inside this update panel, I've got two regular panels and a set of two radio buttons, radio1 and radio2.

On Panel1, I've got 4 drop down lists (lets call it DDL group1), being loaded by the CascadingDropDown Extender, meaning the first box triggers the second, and so on. All 4 DDLs have autopostback enabled, meaning that every time I select a value, a SelectedIndexChanged method is called which loads data from a database, based on the information selected on the last DDL.

On Panel2, I've got the same set up, except that I've only got 2 DDLs (let's call it DLL group 2), also linked as cascading dropdowns. These also have SelectedIndexChanged methods.

DLL Groups 1 and 2 are independent of each other.

For the radio buttons, there is an OnSelectedIndexChanged method per each button.

On each change, I set the SelectedValue of the first CascadingDropDown (on both panels) to null (or nothing in VB).

When I select radio1, panel1 is visible, panel2 is invisible. On the first go, everything works as expected.

When I select radio2, panel2 is visible, panel1 is invisible. Again, on the first go everything works as expected.

Then comes the problem: If i am in radio 2, and go to radio1 and panel 1 comes up, the CascadingDropDowns seemingly have been reset because of the SelectedValue = nothing (null), except that on the first DDL, when I select my first choice, the second DropDownList is activated, however the SelectedIndexChanged method is not being triggered for the first DDL, instead the last selected DDL's method is run, and since the boxes haven't loaded, I get an error.

To be a bit more clear, here´s a small example:

Suppose I clicked radio1. Panel1 with Group1 shows up.

Group1 has boxes City, Store, Department, Shelf.

When I select city, Store is loaded, when i select store, department is loaded, and so on.

The listbox that is being loaded loads the items. In other words, if I select City, the box will show ALL items in a given city.

If I select Store, the listbox will show all items in a given store, and so on.

Let´s suppose on this first try, I selected a City, I selected a Store, and I selected Department. The box should now be showing all the Items in the Department chosen.

Now, suppose I click radio2. Panel2 with Group2 shows up.

Here I only have boxes city, and shelf. Meaning that when I select a city, again, I will get in the listbox all the items in city, and the shelf box will load all of the shelves that belong to city. If i select shelf, i will get the items in a given shelf.

Suppose i selected City X, and shelf y.

I then go back to radio1, panel1 shows up as well as group1.

Remember that on this checkchanged, I have set the SelectedValue = nothing. Thus the list looks as if it were reset.

Except that when I select my city, on my listbox nothing shows up. Instead of the citySelectIndexChanged method to run, the DepartmentSelectedIndexChanged method runs, because it was the last active DDL, and naturally, the listbox doesn't load properly, because at this time, since the CascadingDDL was reset, the department box hasn't been loaded.

I've been breaking my head for days now and can't seem to figure it out...any ideas?


Solution

  • It sounds like the solution is to not reset the SelectedValue of the first cascading dropdown to null in the radio button OnSelectedIndexChanged method.

    If the panels are independent, there shouldn't be any harm in keeping the previously selected value if the user switches back and forth between the radio buttons, right?