动态控件不显示
我正在对某些输入 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您仅创建了一个复选框并尝试将其添加到多个占位符。将控件添加到容器会将其从其先前的父级中删除。尝试创建 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.