Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

Am developing a project in which am getting dynamic text boxes on button click, am not getting how to insert data in dynamic text boxes to data base on clicking submit button.Its urgent help me.

my .cs page looks like this

C#
protected void btn1_Click(object sender, EventArgs e)
    {
        int a = 3;
        for (; a <= 5; a++)
        {
            TextBox lndline = new TextBox();
            lndline.ID = "lndline_txt" + a;
            r1_tc2.Controls.Add(lndline);
            Literal li1 = new Literal();
            li1.Text = "";
            r1_tc2.Controls.Add(li1);
        }
        int b = 1;
        if (b==1)
        {
            btn1.Enabled = false;
        }
    }


help me inserting the data to database.
Posted
Updated 18-May-12 21:10pm
v2

Since you haven't posted anything that's related to the insertion in the database, the list of the steps are:
- Open a connection, see: SqlConnection[^]
- Create an SqlCommand[^]
- Add proper parameters, see SqlParameter[^]
- Set the values of the parameters
- Start a transaction, see SqlTransaction[^]
- Execute the command
- Commit or rollback the transaction depending on the success of the execution
- Close the connection
- Dispose the objects
 
Share this answer
 
Use following
C#
List<string> list_txt_values=GetTxtValues();// Here you gets values of dynamically //created text boxes
// Now Call Your Function To Insert values in Database 

List<string> GetTxtValues()
{
List<string> list_txt_values = new List<string>();
  foreach(Control ctr in r1_tc2.Controls)
  {
    if(ctr.GetType().Name=="TextBox" && ((TextBox)ctr).Id.Contains("lndline_txt"))
    {
      list_txt_values.Add(((TextBox)ctr).Text) ;
    }
  }
return list_txt_values; 
}
</string></string></string></string>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900