您的位置:首页 > 编程语言 > ASP

<asp.net> 按一次button, 添加一个textbox

2013-08-09 20:42 621 查看
namespace Test
{
public partial class WebForm1 : System.Web.UI.Page
{
static int i = 1;
static List<TextBox> txtList = new List<TextBox>();

protected void Page_Load(object sender, EventArgs e)
{
RestoreTextBox();
}

protected void btnNew_Click(object sender, EventArgs e)
{
TextBox tx = new TextBox();
tx.ID = "txt" + i;
this.PlaceHolder1.Controls.Add(tx);
txtList.Add(tx);
tx.Text = i.ToString();
i++;

}

public void RestoreTextBox()
{
foreach (TextBox tx in txtList)
{
if (tx != null)
{
this.PlaceHolder1.Controls.Add(tx);
}
}

}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: