创建动态文本框 [英] creating Dynamic textBoxes
本文介绍了创建动态文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i想要创建动态数量的文本框
i使用此代码
Hi,
i want to create a dynamic number of textboxes
i used this code
TextBox box = new TextBox();
box.Text = "aa" + i.ToString();
box.ID = i.ToString();
form1.Controls.Add(box);
但它只创建一次文本框
我需要做什么才能创建所需的内容?我正在使用asp.net c#
but it creates the textbox one time only
what i have to do to create as much as needed ? i am using asp.net c#
推荐答案
用循环包围它。例如,如果您需要十个文本框:
Surround it with a loop. For example, if you want ten text boxes:
for (int i = 1; i <= 10; i++)
{
TextBox box = new TextBox();
box.Text = "aa" + i.ToString();
box.ID = i.ToString();
form1.Controls.Add(box);
}
但你真的应该在form1类和实例中这样做 - 而不是在它之外。让一个班级来处理它自己的内容!
But you should really, really be doing this within the form1 class and instance - not outside it. Let a class take care of it''s own content!
这篇关于创建动态文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文