You must Sign In to post a response.
  • Category: Windows 8

    How to add multiple textboxes and inserting to a DB

    Hello everyone,

    I am trying to add a button so if a user clicks that button, it will add a new text box and a drop down list.

    After that, there will be another box to save those textboxes and dropdownlists to a database.

    How do I do that? I searched the Internet but with no luck
    Also, I want those all text boxes to be inserted in one field in a database table.

    Thank you,
  • #761025
    Hi
    Moe

    You can try this code

    Client Side


    <asp:Button ID="BtSubmit" runat="server" Text="Submit" OnClick="BtSubmit_Click" />

    <asp:Button ID="BtFindControl" runat="server" Text="Save To DB" OnClick="BtFindControl_Click" />


    Server Side


    TextBox txt = new TextBox();
    DropDownList ddl = new DropDownList();
    protected void BtSubmit_Click(object sender, EventArgs e)
    {
    txt.ID = "TxtName";
    this.form1.Controls.Add(txt);

    ddl.ID = "ddlName";
    ddl.Items.Add("India");
    ddl.Items.Add("SriLanka");
    ddl.Items.Add("Pakistan");
    ddl.Items.Add("South Africa");
    this.form1.Controls.Add(ddl);
    }

    protected void BtFindControl_Click(object sender, EventArgs e)
    {
    SqlConnection con = new SqlConnection(strCon);
    con.Open();
    SqlCommand sqlcm = new SqlCommand("Insert into TestRecord values('" + txt.Text + " " + ddl.SelectedItem.Text + "')", con);
    sqlcm.ExecuteNonQuery();
    }

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761027
    Hello Moe,

    We have already provided you the solution on the link :
    http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=342470

    Then why did you post the same question again. You should understand that code and try to work on that code. We are here to help you to solve your problem. You should also try for working and improving the code we have provided to you.

    Hope you understand.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761106
    You should have responded to my last comment on that thread nirav instead of wasting your time talking non-sense here.

  • #761107
    Hello Moe,

    I have created the project for you and provided you the source code also. You should work on that code also to get exact output.

    For your kind info we are also a contributor here same as you.

    So please mind your language while responding to the thread.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761112
    Closing as it is a duplicate to: http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=342470
    Thanks & regards,
    Gaurav Kumar Arora
    Site Coordinator - DNS
    My blog - http://gaurav-arora.com


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.