TableCell中如何动态插入TextBox控件 ( 积分: 50 )

A

airjing

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在页面中动态生成一个TextBox,部分代码如下。在Page_load和Page_OnInit中调用,提示“类型“TextBox”的控件“tbName”必须放在具有 runat=server 的窗体标记内。 ”请问注释块中的代码应该如何写?
//第二行
TableRow tr2=new TableRow();
TableCell tc21=new TableCell();
tc21.Text="公司名称";
tc21.Font.Size=12;
TableCell tc22=new TableCell();
//////////
TextBox tbName=new TextBox();
tbName.ID="tbName";
tbName.Text="Name";
tbName.Width=60;
tc22.Controls.Add(tbName);
//////////
tr2.Cells.Add(tc21);
tr2.Cells.Add(tc22);
 
解决了。在页面添加一下代码
<form id="Form1" method="post" runat="server">
<asp:placeHolder id="ph1" runat="server"></asp:placeHolder
</form>
然后ph1.Controls.Add(TextBox)即可。
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
932
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部