重置 CascadingDropBoxList 时出现的问题:S

发布于 2024-12-17 21:49:07 字数 1727 浏览 2 评论 0原文

感谢您的阅读,这篇文章有点长,但我希望有人能帮助我!

我进行了以下设置:

在网络应用程序上,我有一个更新面板

在这个更新面板中,我有两个常规面板和一组两个单选按钮,radio1 和 radio2。

在 Panel1 上,我有 4 个下拉列表(我们称之为 DDL group1),由 CascadingDropDown Extender 加载,这意味着第一个框会触发第二个框,依此类推。所有 4 个 DDL 都启用了自动回发,这意味着每次我选择一个值时,都会调用一个 SelectedIndexChanged 方法,该方法根据最后一个 DDL 中选择的信息从数据库加载数据。

在 Panel2 上,我进行了相同的设置,只是我只有 2 个 DDL(我们称之为 DLL 组 2),也作为级联下拉列表链接。这些也有 SelectedIndexChanged 方法。

DLL 组 1 和 2 彼此独立。

对于单选按钮,每个按钮都有一个 OnSelectedIndexChanged 方法。

每次更改时,我将第一个 CascadingDropDown(两个面板上)的 SelectedValue 设置为 null(或在 VB 中设置为空)。

当我选择radio1时,panel1可见,panel2不可见。第一次,一切都按预期进行。

当我选择radio2时,panel2可见,panel1不可见。再说一遍,第一次一切都按预期进行。

那么问题来了:如果我在广播 2 中,转到广播 1 并且面板 1 出现,CascadingDropDowns 似乎已被重置,因为 SelectedValue = Nothing (null),除了在第一个 DDL 上,当我选择第一个时选择,第二个 DropDownList 被激活,但是第一个 DDL 没有触发 SelectedIndexChanged 方法,而是运行最后一个选定的 DDL 方法,并且由于框尚未加载,我得到一个 错误。

为了更清楚一点,这里有一个小例子:

假设我点击了 radio1。将显示带有 Group1 的 Panel1。

Group1 有盒子 City、Store、Department、Shelf。

当我选择城市时,会加载商店,当我选择商店时,会加载部门,依此类推。

正在加载的列表框会加载项目。换句话说,如果我选择城市,该框将显示给定城市中的所有项目。

如果我选择“商店”,列表框将显示给定商店中的所有项目,依此类推。

假设在第一次尝试中,我选择了一个城市,选择了一家商店,然后选择了部门。该框现在应该显示所选部门中的所有项目。

现在,假设我单击 radio2。将显示带有 Group2 的 Panel2。

这里我只有盒子城和货架。这意味着当我再次选择一个城市时,我将在列表框中获取该城市中的所有项目,并且货架框将加载属于该城市的所有货架。如果我选择货架,我将获得给定货架中的物品。

假设我选择了城市 X,货架 y。

然后我返回到 radio1、panel1 以及 group1。

请记住,在此检查更改中,我已将 SelectedValue 设置为无。因此,该列表看起来就像被重置了一样。

除了当我选择我的城市时,我的列表框中没有显示任何内容。不是运行 citySelectIndexChanged 方法,而是运行 DepartmentSelectedIndexChanged 方法,因为它是最后一个活动的 DDL,自然地,列表框无法正确加载,因为此时,自从 CascadingDDL 被重置后,部门框还没有被加载。已加载。

我已经绞尽脑汁好几天了,似乎无法弄清楚......有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱她像谁 2024-12-24 21:49:07

听起来解决方案是不要在单选按钮 OnSelectedIndexChanged 方法中将第一个级联下拉列表的 SelectedValue 重置为 null。

如果面板是独立的,那么当用户在单选按钮之间来回切换时,保持先前选择的值应该不会有任何损害,对吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文