日期:2014-05-17  浏览次数:20436 次

asp.net动态添加TextBox控件并获取这些动态添加的TextBox的Text属性
如题所示,能在服务器端实现吗?

------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
    {
        TextBox txtbx= null;    
        DropDownList ddl = null;

        for (int i = 0; i < 4; i++)
        {               
            txtbx= new TextBox();
            txtbx.ID = "mytxt" + i; 
            txtbx.Text = "mytxt" + i;            

            pnlButton.Controls.Add(txtbx);    

            ddl= new DropDownList();
            ddl.ID = "mydropdown " + j;
            ddl.Text = "mydropdown " + j;
            ddl.Items.Add("Hii");
            ddl.Items.Add("Hello");
            ddl.AutoPostBack = true;
            ddl.SelectedIndexChanged += new EventHandler(ddl_Click);

            pnlButton.Controls.Add(ddl);

            Literal lit = new Literal();
            lit.Text = "</br></br>";
            pnlButton.Controls.Add(lit);
        }