如何使用级联下拉列表设置默认选择

如何使用级联下拉列表设置默认选择

本文介绍了如何使用级联下拉列表设置默认选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种方案,让用户使用两个层叠的下拉列表(一个AJAX Control Toolkit Extenders)来选择他的州和城市.
我还有一个编辑部分,他可以在其中更新州和城市.如果他一开始没有任何内容,则数据库条目为空.在这种情况下,我只向他显示级联下拉菜单,然后他选择一个有效的条目.
谈到我面临的问题,问题在于他实际输​​入数据的时间.如果他已经保存了数据,则必须确保下拉菜单中已选择了那些项目.现在在页面未回发时加载页面时,我尝试进行选择.但是我得到了

I have a scenario where I let a user select his state and city by using two cascading dropdown list (one of AJAX Control Toolkit Extenders).
I also have an edit section where he can update the state and city. If he does not have anything at the first place, the database entry is null. In that scenario, I simply show him the cascading drop downs and he selects a valid entry.
Coming to the issue I am facing, the issue is when he actually has entered the data. If he has already saved the data, I have to make sure that the dropdown has those items selected. Now on the page load when the page is not postback, I tried to make a selection. However I get a

NullReferenceException

.
我如何确保如果某个用户确实存在某个条目,则该条目应相应地绑定下拉菜单?

.
How do I make sure that if an entry does exist for a user, it should bind the dropdowns accordingly?

推荐答案

SelectedValue 

的属性,非常适合解决此情况.

which is just perfect to solve this scenario.



这篇关于如何使用级联下拉列表设置默认选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 12:26