0

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.

Tabish Sarwar
  • 1,505
  • 1
  • 11
  • 18

2 Answers2

0

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.

xtrem
  • 1,737
  • 12
  • 13
0
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 });
    }
}
WoLfulus
  • 1,948
  • 1
  • 14
  • 21