简体   繁体   English

动态复选框。检查if语句

[英]Dynamic Checkbox.Checked if statement

Below is my code, the code creates a new CheckBox for each HyperLink, it then names each CheckBox with the name of the Hyperlink. 下面是我的代码,该代码为每个HyperLink创建一个新的CheckBox,然后用Hyperlink的名称命名每个CheckBox。 I then have an IF statement which checks whether the dynamically created CheckBox has been checked. 然后,我有一条IF语句,该语句检查是否已检查动态创建的CheckBox。 If it has, display the name of the CheckBox in a label. 如果有,请在标签中显示CheckBox的名称。

However.. the label is not populating. 但是..标签没有填充。 I have tested everything and the label gets populated if i do it manually. 我已经测试了所有内容,如果我手动进行操作,则会填充标签。 The label has saved view state aswell. 标签也已保存视图状态。 Any ideas? 有任何想法吗? :) :)

foreach (HyperLink folder in folderList)
            {
                CheckBox checkbox = new CheckBox();
                checkbox.Text = folder.Text.ToString();
                folder.Controls.Add(check);
                checkbox.EnableViewState = true;
                checkbox.AutoPostBack = true;    

                if(check.Checked)
                {
                    selectedFolder.Text = check.Text.ToString();
                }

            }

It appears to me that you are not leaving any time for the checkbox to be checked (user input). 在我看来,您没有留下任何时间来选中该复选框(用户输入)。 You should use an event handler or something similar to capture the event that a checkbox is checked. 您应该使用事件处理程序或类似的方法来捕获选中复选框的事件。

Also, I don't see "check" being defined anywhere.. Do you mean "checkbox" instead of "check"? 另外,我看不到任何地方都定义了“检查”。您是说“检查”而不是“检查”吗?

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

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