在这个项目中,我使用用户输入动态创建文本框:
int ReqPO = Convert.ToInt32(txtReqPONum.Text);
int n = ReqPO;
for (int i = 0; i < n; i++)
{
TextBox MyTextBox = new TextBox();
//Assigning the textbox ID name
MyTextBox.ID = "txtPOAmount" + "" + ViewState["num"] + i;
this.Form.Controls.Add(MyTextBox);
}编辑的是我得到的地方,这并不是太远。现在我只是犯了很多错误
Table table1 = new Table();
TableRow tr = null;
TableCell tc = null;
int ReqPO = Convert.ToInt32(txtReqPONum.Text);
int n = ReqPO;
for (int a = 0; a < n; a++)
{
tr = new TableRow();
for (int b = 0; b < n; b++)
{
TextBox MyTextBox = new TextBox();
for (int c = 0; c < 3; c++)
{
tc = new TableCell();
table1.Rows.Add(tc);
}
//Assigning the textbox ID name
MyTextBox.ID = "txtPOAmount" + "" + ViewState["num"] + b;
this.Form.Controls.Add(MyTextBox);
}
table1.Rows.Add(tr);
}
this.Form.Controls.Add(table1);问题是,我在向导中使用它,并且希望显示新的textbox字段,这些字段出现在表中的它们自己的行中。目前,它们在asp:wizard上一个按钮和下一个按钮下面并排显示。
发布于 2013-10-04 15:06:36
如果要在表中显示动态文本框,则只需动态创建HTML表即可。创建TR (行),然后创建TD (单元格),然后创建textbox,将其添加到单元格中,然后将单元格添加到行中,将单元格添加到表和表中,然后将其添加到您想要放置的控件中。
如果您要在网页中创建HTML,那么只需添加runat=" server“并给它一个ID,就可以在服务器端显示它,并且您可以像任何其他控件一样操作它。
换句话说,不要将控件添加到窗体中,而是将其添加到特定的父控件中。
<asp:Wizard runat="server">
<WizardSteps>
<asp:WizardStep>
<table runat="server" id="tblTextBoxes">
</table>
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>tblTextBoxes.Controls.Add(new TextBox() {ID = "txtNewTextBox",Text = "Text of new control"});
(上面的代码仅限于,不能直接将TextBox添加到表中,但可以在TR标记中添加到TD )。
https://stackoverflow.com/questions/19184149
复制相似问题