javascript/ajax 填充的下拉列表中的 Gridview SQL 参数为 null
我的问题类似于 如何使用由 AJAX/PHP 填充的 DropDownList 中选定值的值,但我使用的是 ASP.NET,而不是 PHP。
我有一个下拉列表,它通过 ajax 由另一个下拉列表的当前值填充。因此,如果 DDL A 是“NY”,则 DDL B 将填充与“NY”相关的不同数据。我需要将该数据发回服务器,因为这会影响 SQLDataSource 参数。但是,据我所知,回发后该值始终为空,导致 gridview 为空。
如何强制 ASP 读取下拉列表的当前值?
My issue is similar to How to use the Value of a Selected Value from a DropDownList populated with AJAX/PHP but I am using ASP.NET, not PHP.
I have a dropdownlist that is populated by another dropdownlist's current value through ajax. So if DDL A is 'NY', DDL B is populated with different data relating to 'NY'. I need that data to be posted back to the server because this affects an SQLDataSource parameter. However, as far as I can tell, the value is always null after postback resulting in the gridview to be empty.
How can I force ASP to read the dropdownlist's current value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DDL B 在客户端填充 - 服务器端不存在任何元素。这就是为什么在服务器端,您不会获得任何失控的价值。但是,您始终可以在请求发布数据中查找 -
Request.Form[DDLB.UniqueID]
以获取选定的下拉值。编辑:通常,在服务器控件可能回发无效值(例如,其选项中不存在下拉返回值)的情况下,您需要关闭页面事件验证。
DDL B is populated at client side - there are no elements present in it on server side. That's why on server side, you will not get any value out of control. However, you can always lookup in the request post data -
Request.Form[DDLB.UniqueID]
to get the selected drop-down value.Edit: typically, you need to turn page event validation off in scenarios where your server control may post back invalid value (for example, a drop down returning value not present in its options).