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

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);
                }
            }

        }

    }
}


 

猜你喜欢

转载自blog.csdn.net/shylx123/article/details/9864109