如何动态添加一行文本框?我可以使用AJAX或任何其他工具箱的控件吗? [英] How to genarate a row of text boxes dynamically? Can I use an AJAX or any other toolkit's control?
本文介绍了如何动态添加一行文本框?我可以使用AJAX或任何其他工具箱的控件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何动态添加一行文本框?我可以使用AJAX或任何其他工具包的控件吗?
例如:单击添加另一个"按钮后,应生成一行6个文本框.
请帮助我.
How to genarate a row of text boxes dynamically? Can I use an AJAX or any other toolkit''s control??
For eg: After clicking "add another" button, a row of 6 text boxes should be generated.
Please help me.
推荐答案
试试这个
Hi ,
Try this
int countTimes = 0;
protected void Button2_Click(object sender, EventArgs e)
{
if (ViewState["countTimes"] == null)
{
countTimes = 1;
}
else
{
countTimes = Convert.ToInt32(ViewState["countTimes"]);
}
for (int i = 0; i < countTimes; i++)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
TextBox txt = new TextBox();
txt.ID = "txt"+i;
TextBox txt1 = new TextBox();
txt1.ID = "txt" + i;
TextBox txt2 = new TextBox();
txt2.ID = "txt" + i;
TextBox txt3= new TextBox();
txt3.ID = "txt" + i;
TextBox txt4 = new TextBox();
txt4.ID = "txt" + i;
TextBox txt5 = new TextBox();
txt5.ID = "txt" + i;
TextBox txt6 = new TextBox();
txt6.ID = "txt" + i;
cell.Controls.Add(txt);
cell.Controls.Add(txt1);
cell.Controls.Add(txt2);
cell.Controls.Add(txt3);
cell.Controls.Add(txt4);
cell.Controls.Add(txt5);
cell.Controls.Add(txt6);
row.Controls.Add(cell);
Table1.Controls.Add(row);
}
countTimes = countTimes + 1;
ViewState.Add("countTimes", countTimes);
}
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<br />
<asp:Table ID="Table1" runat="server">
</asp:Table>
</div>
最好的问候
M.Mitwalli
Best Regards
M.Mitwalli
尝试一下.可能会有所帮助
Try this .may be help
Table tb = new Table();
tb.BorderWidth = Unit.Pixel(5);
for (int i = 1; i <= Convert.ToInt32(TextBox1.Text ); i++)
{
TableRow tr = new TableRow();
for (int j = 1; j <= 3; j++)
{
TableCell td = new TableCell();
TextBox c_text = new TextBox();
c_text.Visible = true;
c_text.Text = "R"+i.ToString()+j.ToString();
c_text.ID = "R" + i.ToString() + j.ToString();
td.Controls.Add(c_text);
tr.Cells.Add(td);
tb.Rows.Add(tr);
form1.Controls.Add(tb);
}
这篇关于如何动态添加一行文本框?我可以使用AJAX或任何其他工具箱的控件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文