开发者

ASP.NET: Format dynamically create controls

I create controls for data input on the fly. It consist of set of (rows)开发者_如何学运维 labels and textboxes/comboboxes.

Panel1.Controls.Add(new LiteralControl("<br>"));
Label lbl = new Label();
lbl.Text = descTest;
Panel1.Controls.Add(lbl);
Panel1.Controls.Add(new LiteralControl(" : "));
Panel1.Controls.Add(ddList);

Now the labels and textboxes of all the rows are not aligned. How can it be done? I need to rows & columns?


You can use asp:Table instead, it will make lot easier for you to format things in rows and columns:

aspx:

<asp:Table ID="table" runat="server">
</asp:Table>

Code behind:

TableCell cell1 = new TableCell();
cell1.Text = descTest;

TableCell cell2 = new TableCell();
cell2.Controls.Add(new TextBox());

TableRow row = new TableRow();
row.Cells.Add(cell1);
row.Cells.Add(cell2);

table.Rows.Add(row);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜