在面板中找不到动态创建的图形复选框.控制列表

本文关键字:图形 复选框 控制 列表 创建 动态 找不到 | 更新日期: 2023-09-27 18:06:35

我在面板内创建基于数据库值的动态图形复选框。但当我试图改变选中状态,而点击选择所有复选框。什么也不会发生。我在里面找不到任何控件

<%@ Register Assembly="EeekSoft.Web.Controls" Namespace="EeekSoft.Web.Controls" TagPrefix="cc1" %>                                 <div style="overflow: auto; height: 462px; width: 386px; margin-top: 0px;">
      <asp:Panel ID="optionPanel" runat="server" Height="479px" Width="380px">
      <cc1:GraphicalCheckBox ID="chkSelectAll" runat="server" CheckedImg="images/checked.gif" OnCheckedChanged="chkSelectAll_CheckedChanged"
      UncheckedImg="images/unchecked.gif" UncheckedOverImg="images/unchecked.gif" CheckedOverImg="images/checked.gif"
                                    UncheckedDisImg="images/unchecked_disabled.gif" Style="cursor: hand;" Font-Size="100%" AutoPostBack="true"/>
      <span class="survey_wizard_title" id="lblSelectAll" runat="server">Select All</span>
      </asp:Panel>
</div>

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack && Request["SurveyID"] != null)
    {
        surveyID = Convert.ToInt32(Request["SurveyID"]);
        PopulateParticipants();
    }
}private void PopulateParticipants()
{foreach (OptionPool opt in respOptions)
{
    Panel row = new Panel();
    GraphicalCheckBox cb = new GraphicalCheckBox();
    row.Attributes.Add("class", "surveyCheckbox");
    cb.ID = Convert.ToString(opt.id);
    cb.Attributes.Add("value", opt.id.ToString());
    cb.Text = opt.data;
    cb.Style.Add("cursor", "hand");
    cb.Font.Size = new FontUnit("100%");
    cb.UncheckedImg = "images/unchecked.gif";
    cb.UncheckedOverImg = "images/unchecked.gif";
    cb.CheckedImg = "images/checked.gif";
    cb.CheckedOverImg = "images/checked.gif";
    cb.UncheckedDisImg = "images/unchecked_disabled.gif";
    row.Controls.Add(cb);
    optionPanel.Controls.Add(row);
}}

protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
    if (chkSelectAll.Checked == true)
    {
        foreach (Control child in optionPanel.Controls)
        {
            if (!(child is GraphicalCheckBox))
                continue;
            if ((child is GraphicalCheckBox))
            {
                (child as GraphicalCheckBox).Checked = true;
            }
        }
    }
}

optionPanel。控件没有列出任何上述动态创建的复选框。

在面板中找不到动态创建的图形复选框.控制列表

在ASP中使用动态控件。您需要在Page_Init方法中重新创建它们,并且每次使用相同的id