更新下拉列表 [英] update dropdown list

查看:57
本文介绍了更新下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个下拉列表:"countrydropdown","statedropdown"和"citydropdown".所有下拉列表都相互连接.如果我们更改"countrydropdown"中的值,则"statedropdown"中的列表将自动更改.
现在,我想以编程方式更改"countrydropdown","statedropdown"和"citydropdown"的值,但是"countrydropdown"列表的任何更改都不会影响"statedropdown"的列表.请建议我如何以编程方式刷新dropdownlist.有问题吗?

如果是这样,那么您将需要:

1)创建一个类级别的bool,上面写着我正在更新-忽略事件"

2)禁用事件处理程序,直到更新完成.

我会选择前者.


使用 SelectedValueChanged 事件.它会起作用.

要标识当前组合的选定值,请使用 ComboBox1.Text ComboBox1.SelectedItem 获取下一个组合框的值.
如果使用的是ASP.NET,请检查

AutoPostBack="TRUE"


AutoPostBack属性用于设置或返回用户在TextBox控件中按下"ENTER"或"TAB"时是否发生自动回发.

如果将此属性设置为TRUE,则启用自动回发,否则为FALSE.默认值为FALSE.


I have three dropdownlists ''countrydropdown'', ''statedropdown'', and ''citydropdown''. All the dropdownlists are connected to each other. If we change a value in ''countrydropdown'', the list in ''statedropdown'' will change automatically.
Now I wanted to change value of ''countrydropdown'', ''statedropdown'' and ''citydropdown'' programatically, but any change of ''countrydropdown'' list does not affect list of ''statedropdown''. Please suggest me how to refresh dropdownlist programatically.

解决方案

I assume you are handling an event from "countrydropdown" that updates "statedropdown", and this is what gives you the problem?

If so, then you will need to either:

1) Create a class level bool which says "I''m updating - ignore events"
or
2) Disable the event handler until updates are complete.

I would go with the former.


Use SelectedValueChanged event. it will work.

to idintify the selected value of current combo use ComboBox1.Text or ComboBox1.SelectedItem to get value for next combobox.
if you are using ASP.NET then check the

AutoPostBack="TRUE"


The AutoPostBack property is used to set or return whether or not an automatic post back occurs when the user presses "ENTER" or "TAB" in the TextBox control.

If this property is set to TRUE the automatic post back is enabled, otherwise FALSE. Default is FALSE.


这篇关于更新下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆