如何使用级联下拉列表设置默认选择 [英] How to set a default selection with cascading dropdown list

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

问题描述

我有一种方案,让用户使用两个层叠的下拉列表(一个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?

推荐答案

我刚刚找到了解决问题的方法.可以在扩展器本身上进行设置.扩展程序具有名为
I just found the solution for the problem. It can be set on the extender itself. The extender has a property called
SelectedValue 

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

which is just perfect to solve this scenario.


对象引用未设置为的实例一个对象

当您尝试使用属性或调用对象的方法为null时,会发生此错误.更多详细信息:此处 [
Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.

Since you have not shared the code, it''s difficult to point possible places but the fix would be to handle the scenario such that whenever there is data for person in Db, fetch it and set it from the default selection list.

Steps:
1. Populate the State dropdown.
2. Set the selected value of dropdown based on the DB selection value for that user
3. Get the cities of the state based on the selection
4. populate the cities dropdown based on the cities fetched
5. Set the seletced value of dropdown based on the DB selected value for that user

Try!


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

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