Create Dynamic Textboxex and Get values

Sep 22 2011 12:42 AM
Hello,
 
I want to create more then one text box at run time and also the data of Textbox created on the run time. 
as i forgotten mention that I am creating these dynamic textbox for the SelectedIndexChange event of dropdown 
Below is code that i am using
 

protected void ddlAnswerChoices_SelectedIndexChanged(object sender, EventArgs e)
    {
        Int32 choice=Convert.ToInt32(ddlAnswerChoices.SelectedItem.Value);
        for (int i = 1; i <= choice; i++)
        {
            LiteralControl literal = new LiteralControl();
            literal.Text = "<br /><br />";
            Label newLabel = new Label();
            newLabel.Text = "Choice" + " " + i.ToString();
            newLabel.ID = "lblChoice" + i.ToString();
            newLabel.Attributes.Add("runat","Server");
            this.panelLabel.Controls.Add(newLabel);
            this.panelLabel.Controls.Add(literal); 
        }
 
        for (int j = 1; j <= choice; j++)
        {
            LiteralControl literal = new LiteralControl();
            literal.Text = "<br /><br />";
            TextBox nexText = new TextBox();
            nexText.ID = "txtChoice" + j.ToString();
            nexText.Attributes.Add("runat", "Server");
            panelTextbox.Controls.Add(nexText);
            this.panelTextbox.Controls.Add(literal);
        }
 
    }
 
I am using above code to create the Textbox dynamically.
 

Now i facing trouble how to retrieve the data of the these Textbox after the clicking on the submit button so that i can store the values of there Textboxes to database.
 
what will be code written for the click event of btnSave
 
protected void btnSave_Click(object sender, EventArgs e)
    {
       
    }
 

Thank in advance
 
Deepak Pandey

Answers (2)