简体   繁体   English

dropdownlist是asp.net

[英]dropdownlist is asp.net

I want to display countries and the corresponding states in dropdownlist . 我想在dropdownlist显示国家和相应的州。 Which method is efficient for storing the data in database and displaying it using updatepanel or filling dropdown at client side using javascript. 哪种方法可以有效地将数据存储在数据库中,并使用updatepanel显示数据,或使用javascript在客户端填充dropdown ,效率很高。 I am confused which approach should I follow or is there any other way? 我很困惑应该采用哪种方法,或者还有其他方法吗?

If you need to populate the list when the page is loaded you should use standard binding methods at the server side. 如果在页面加载时需要填充列表,则应在服务器端使用标准绑定方法。 If you need to populate the list when an action is performed later on the page you could use an UpdatePanel which will perform an ajax callback to the server. 如果稍后在页面上执行操作时需要填充列表,则可以使用UpdatePanel,它将对服务器执行ajax回调。 And finally the best option IMHO would be to have a server side action with caching enabled returning a JSON encoded representation of the countries which would be invoked using ajax and bound to a normal <select> without using any server side asp:DropDown... 最后,最好的恕我直言,恕我直言将是启用缓存的服务器端操作返回国家的JSON编码表示形式,该国家/地区将使用ajax调用并绑定到普通<select>而不使用任何服务器端asp:DropDown...

Dear Confused, updatepanel will be better approach as you will not have to reload the whole page. 亲爱的困惑, updatepanel将是更好的方法,因为您不必重新加载整个页面。 But as user may go through the countries using up-down keys it will be easier if you trigger update of panel after user leaves countries dropdownlist. 但是,由于用户可以使用上下键浏览各个国家/地区,因此如果在用户离开国家/地区下拉列表后触发面板更新,将更加容易。

PS:- Updatepanel is also client side approach. PS: Updatepanel也是客户端方法。 If you feel comfortable with jQuery then you can use jQuery ajax to upload states list. 如果您对jQuery感到满意,则可以使用jQuery ajax上传状态列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM