简体   繁体   English

不会针对在运行时创建的下拉列表触发选定的索引更改事件

[英]doesn't fire selected index changed event for a drop down list created on run time

Q: 问:

I have the following case : 我有以下情况:

a button , when clicking on this button , create a drop down list on run time ,and make an event(selected index changed ) for the drop down list.. 一个按钮,单击此按钮时,将在运行时创建一个下拉列表,并为该下拉列表创建一个事件(选择索引已更改)。

but what happen is half the previous scenario , i mean creating the drop down list on run time but it doesn't enter the(selected index changed).. 但是发生的事情是前一种情况的一半,我的意思是在运行时创建一个下拉列表,但没有输入(所选索引已更改)。

i don't know what is the problem? 我不知道是什么问题?

Not sure what the exact scenario is, but every time you postback, you'll have to create the drop down list and register to the event. 不确定确切的情况是什么,但是每次回发时,都必须创建下拉列表并注册该事件。 Couldn't you hide/show and populate the dropdown box on click of the button? 单击按钮后是否可以隐藏/显示并填充下拉框? Have a look at the link for a similar issue. 查看类似问题的链接。

http://www.dreamincode.net/forums/topic/165499-access-selectedindex-of-dropdownlist-created-at-runtime/ http://www.dreamincode.net/forums/topic/165499-access-selectedindex-of-dropdownlist-created-at-runtime/

Haven't tried this myself, but this link might help you, if you must add the control dynamically http://shawpnendu.blogspot.com/2010/04/runtime-add-dynamic-dropdownlist-and.html 自己还没有尝试过,但是如果必须动态添加控件,则此链接可能会对您有所帮助http://shawpnendu.blogspot.com/2010/04/runtime-add-dynamic-dropdownlist-and.html

did you set ddl.AutoPostBack = true; 您是否设置了ddl.AutoPostBack = true; when adding control runtime? 添加控件运行时时?

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

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