Arrange controls in panel in ASP.NET
I want to arrange the controls in a Panel control. For example, I have four labels and four textboxs, I want to put them in a panel like a table without using the VS designer, only use the code. Does an开发者_JS百科yone do it before?
Best Regards,
C#, and use styles to control layout.
Panel pnl = new Panel();
Label lbl1 = new Label();
lbl1.Text = "1";
pnl.Controls.Add(lbl1);
TextBox tb1 = new TextBox();
pnl.Controls.Add(tb1);
Page.Controls.Add(pnl);
label
{
display: inline;
}
You could essential do the same thing Visual Studio does on the back end. Create a new control and set the properties, such as: size, name, text, and location.
I think that you can simply create a custom control that contains a label and a text box. Let's call this control LabeledTextBox. And then on your code simply add 4 instances of LabeledTextBox one after the other. This should provide the look and feel you want.
精彩评论