C#点击按钮添加标签

     
    <asp:Button ID="button1" runat="server" Text="创建" onclick="Button1_Click" />
<asp:Panel ID="Panel1" runat="server"></asp:Panel>


   //静态变量存储控件列表
        static List<TextBox> txtlist = new List<TextBox>();
        //控件id
        static int id = 1;
        protected void Button1_Click(object sender, EventArgs e)
        {
            var txt = new TextBox
            {
                ID = id.ToString(),
                Text = "Sample textbox " + id.ToString()
            };
            this.Panel1.Controls.Add(txt);
            txtlist.Add(txt);
            //id自增1
            id++;
        }
        /// <summary>
        /// 还原控件
        /// </summary>
        void RestoreTextBox()
        {
            foreach (var item in txtlist)
            {
                if (item != null)
                {
                    this.Panel1.Controls.Add(item);
                }
            }
        }
        /// <summary>

  

C#点击按钮添加标签

上一篇:电脑安装Win11专业版出现卡住不动的问题


下一篇:C#中default 、base 、thies关键字用法简介