动态控件不显示

发布于 2024-12-27 18:22:12 字数 841 浏览 2 评论 0原文

我正在对某些输入 XML 创建控件。 然后将控件添加到放置在表中的不同占位符控件中。这是供参考的代码

private void RenderFactorControls(string xml)
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(xml);

        foreach (XmlNode xmlNode in xmlDoc.DocumentElement.ChildNodes)
        {
            CheckBox factorCheckBox = new CheckBox();
            factorCheckBox.ID = "chkBox"+xmlNode.Attributes["id"].Value;
            factorCheckBox.Text = xmlNode.Attributes["id"].Value;

           this.pholderControls1.Controls.Add(factorCheckBox);
           this.pholderControls2.Controls.Add(factorCheckBox);
           this.pholderControls3.Controls.Add(factorCheckBox);
           this.pholderControls4.Controls.Add(factorCheckBox);
           this.pholderControls5.Controls.Add(factorCheckBox);
        }
    }

仅最后一个占位符显示控件。

I am creating controls on some input XML.
The controls are then added to the different PlaceHolder Control which is places in a table. Here is the code for reference

private void RenderFactorControls(string xml)
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(xml);

        foreach (XmlNode xmlNode in xmlDoc.DocumentElement.ChildNodes)
        {
            CheckBox factorCheckBox = new CheckBox();
            factorCheckBox.ID = "chkBox"+xmlNode.Attributes["id"].Value;
            factorCheckBox.Text = xmlNode.Attributes["id"].Value;

           this.pholderControls1.Controls.Add(factorCheckBox);
           this.pholderControls2.Controls.Add(factorCheckBox);
           this.pholderControls3.Controls.Add(factorCheckBox);
           this.pholderControls4.Controls.Add(factorCheckBox);
           this.pholderControls5.Controls.Add(factorCheckBox);
        }
    }

Only the last place holder shows the controls.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月光色 2025-01-03 18:22:12
private void RenderFactorControls(string xml)
{
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(xml);

    foreach (XmlNode xmlNode in xmlDoc.DocumentElement.ChildNodes)
    {
        string id = "chkBox"+xmlNode.Attributes["id"].Value;
        string text = xmlNode.Attributes["id"].Value;

        this.pholderControls1.Controls.Add(new CheckBox() { ID = id, Text = text });
        this.pholderControls2.Controls.Add(new CheckBox() { ID = id, Text = text });
        this.pholderControls3.Controls.Add(new CheckBox() { ID = id, Text = text });
        this.pholderControls4.Controls.Add(new CheckBox() { ID = id, Text = text });
        this.pholderControls5.Controls.Add(new CheckBox() { ID = id, Text = text });
    }
}
private void RenderFactorControls(string xml)
{
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(xml);

    foreach (XmlNode xmlNode in xmlDoc.DocumentElement.ChildNodes)
    {
        string id = "chkBox"+xmlNode.Attributes["id"].Value;
        string text = xmlNode.Attributes["id"].Value;

        this.pholderControls1.Controls.Add(new CheckBox() { ID = id, Text = text });
        this.pholderControls2.Controls.Add(new CheckBox() { ID = id, Text = text });
        this.pholderControls3.Controls.Add(new CheckBox() { ID = id, Text = text });
        this.pholderControls4.Controls.Add(new CheckBox() { ID = id, Text = text });
        this.pholderControls5.Controls.Add(new CheckBox() { ID = id, Text = text });
    }
}
旧城空念 2025-01-03 18:22:12

您仅创建了一个复选框并尝试将其添加到多个占位符。将控件添加到容器会将其从其先前的父级中删除。尝试创建 5 个不同的复选框。

You created only One CheckBox and are trying to add it to multiple placeholders. Adding a control to a container removes it from its previous parent. Try creating 5 different checkboxes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文