动态添加多个文本框问题
我想实现以下功能:每按一次按钮就自动生成两个或多个文本框。
一次生成一个的代码已经找到了,不知道怎么改,c#的,各位高手帮帮忙:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
for (int i = 0; i < TextBoxsList.Count;i++)
{
string txtID = TextBoxsList[i].ToString();
TextBox tmp = new TextBox();
tmp.ID = txtID;
Page.Form.Controls.Add(tmp);
tmp.Text = Request.Form[txtID].ToString();
}
}
}
private ArrayList TextBoxsList
{
get
{
if (ViewState["myTextBoxsList"] == null)
return new ArrayList();
else
return ViewState["myTextBoxsList"] as ArrayList;
}
set
{
ViewState["myTextBoxsList"] = value;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox tmp = new TextBox();
tmp.ID = "TextBox" + TextBoxsList.Count.ToString();
Page.Form.Controls.Add(tmp);
ArrayList array = TextBoxsList;
array.Add(tmp.ID);
TextBoxsList = array;
}
}