Friday, January 22, 2010

How do you add controls to a form at runtime in ASP.NET?

I can use form1.Controls.Add(myControl) or page.Controls.Add(myControl)





but all of the controls are laid out left to right. I need to insert line breaks so they go top to bottom





instead of label textbox label textbox label textbox





I need





label





textbox





label





textbox





I have tried adding an HTML linebreak to labels but that doesn't do anything. The code i'm working with is posted below:











string[] files = GetCode();





Color labelColor = Color.Red;





Label spacer = new Label();





spacer.Text = ';
';;





for (int i = 0; i %26lt; files.Length;)





{





// currently set to the file name





// create a label for the code





Label label = new Label();





label.ForeColor = labelColor;





label.Text = files[i];








i++; // move on to the code





// currently set to code for this file





// create a TextBox for this file





TextBox textBox = new TextBox();





textBox.Text = files[i];








i++; // set up i for the next file





// add the controls to the site





form1.Controls.Add(label);





Page.Controls.Add(spacer);





form1.Controls.Add(spacer);





form1.Controls.Add(textBox);





form1.Controls.Add(spacer);





form1.Controls.Add(spacer);





}How do you add controls to a form at runtime in ASP.NET?
if you acquire DRAM it will reset

No comments:

Post a Comment