How to create a table for Placeholder controls
-
Hello, I have created a placeholder to will contain labels and textboxes based on the users choice from a dropdown. I would like to place every label and textbox in a seperate td in a table. How can I create a td for every label and textbox? Thanks. Here is part of the code: void CreateLabelsTextBoxes() { int n = Int32.Parse(NumOfQuestionsDropDown.SelectedItem.Value); // create n Labels and TextBoxes, and add them to the PlaceHolder TextBoxesHere for (int i = 0; i < n; i++) { PlaceHolder1.Controls.Add(new Label()); PlaceHolder1.Controls.Add(new TextBox()); } // Set the Text property of each Label IterateThroughChildren(this); } void IterateThroughChildren(Control parent) { int count = 1; foreach (Control c in parent.Controls) { if (c.GetType().ToString().Equals("System.Web.UI.WebControls.Label") && c.ID == null) { ((Label)c).Text = "Question" + count; count++; } Response.Write("Type= " + c.GetType() + "
"); if (c.Controls.Count > 0) { IterateThroughChildren(c); } } } protected void NumOfQuestionsDropDown_SelectedIndexChanged(object sender, EventArgs e) { CreateLabelsTextBoxes(); }