C#点击按钮添加标签

时间:2021-09-06
本文章向大家介绍C#点击按钮添加标签,主要包括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>

  

原文地址:https://www.cnblogs.com/liuguiqing/p/15233348.html