Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Dynamic control add in form and finally store in to database

Dynamic control add in form and finally store in to database

Scheduled Pinned Locked Moved ASP.NET
cssdatabase
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 3879881
    wrote on last edited by
    #1

    Hi guys i have posted this one already, But i didnt get exact o/p. So once again i am posting here, Actually in one link button click i have to add 3 textbox in my form..., After enter in that textbox if my enduser need to fill one more set of records, if he click that link button again, it have to add again 3 more textbox like this i need..........., Finally when he click submit button the datas have to store into my database..., Some guys said to use gridview..., Suppose if i go for gridview in footer if i tell three textbox in template columns..., In page load there is no values in my grid..., So it wont show the footer template column..., So i cant go for gridview also now, Give me some ideas to solve this...,

    Thanks & Regards, NeW OnE, please don't forget to vote on the post

    B C 2 Replies Last reply
    0
    • M Member 3879881

      Hi guys i have posted this one already, But i didnt get exact o/p. So once again i am posting here, Actually in one link button click i have to add 3 textbox in my form..., After enter in that textbox if my enduser need to fill one more set of records, if he click that link button again, it have to add again 3 more textbox like this i need..........., Finally when he click submit button the datas have to store into my database..., Some guys said to use gridview..., Suppose if i go for gridview in footer if i tell three textbox in template columns..., In page load there is no values in my grid..., So it wont show the footer template column..., So i cant go for gridview also now, Give me some ideas to solve this...,

      Thanks & Regards, NeW OnE, please don't forget to vote on the post

      B Offline
      B Offline
      Bardy85
      wrote on last edited by
      #2

      You can still show a gridview if it is empty. http://www.google.com/search?hl=en&client=opera&rls=en&hs=hiy&q=show+empty+gridview&btnG=Search There quite a few examples here, for how to show a gridview when there no data.

      1 Reply Last reply
      0
      • M Member 3879881

        Hi guys i have posted this one already, But i didnt get exact o/p. So once again i am posting here, Actually in one link button click i have to add 3 textbox in my form..., After enter in that textbox if my enduser need to fill one more set of records, if he click that link button again, it have to add again 3 more textbox like this i need..........., Finally when he click submit button the datas have to store into my database..., Some guys said to use gridview..., Suppose if i go for gridview in footer if i tell three textbox in template columns..., In page load there is no values in my grid..., So it wont show the footer template column..., So i cant go for gridview also now, Give me some ideas to solve this...,

        Thanks & Regards, NeW OnE, please don't forget to vote on the post

        C Offline
        C Offline
        chandralekha
        wrote on last edited by
        #3

        For adding textboxes dynamicaly into a form you can either add textbox controls to a form directly or to a placeholder control inside the form.For retriving values correctly i suggest you to place controls inside a placeholder. You want to create 3 Textboxes in each link button click.Here what i had done is I placed a dropdownlist with items 1,2,3 ..etc.According to the selected item value of the dropdownlist that much set of 3 Textboxes is generated. For that first I place a DropDownList1,PlaceHolder1 and Button1 in the form. My code follows protected void Page_Load(object sender, EventArgs e) { for (int i = 0; i < Convert.ToInt16(DropDownList1.SelectedItem.Text); i++) { PlaceHolder p2 = new PlaceHolder(); p2.ID = "p2" + i; PlaceHolder1.Controls.Add(p2); for (int j = 0; j < 3; j++) { TextBox tb = new TextBox(); tb.ID = "TextBoxg"+i + j; p2.Controls.Add(tb); RequiredFieldValidator f1 = new RequiredFieldValidator(); f1.ControlToValidate = "TextBoxg" + i+j; ; f1.ErrorMessage ="*"; p2.Controls.Add(f1); p2.Controls.Add(InsertBreaks(1)); } p2.Controls.Add(InsertLineBreaks(2)); } } private static Label InsertBreaks(int breaks) { Label lblBreak = new Label(); for (int i = 0; i < breaks; i++) { lblBreak.Text += " "; } return lblBreak; } private static Label InsertLineBreaks(int breaks) { Label lblLineBreak = new Label(); for (int i = 0; i < breaks; i++) { lblLineBreak.Text += "
        "; } return lblLineBreak; } protected void Button1_Click(object sender, EventArgs e) { string[] data = new string[3]; foreach (Control c in PlaceHolder1.Controls) { int yu = 0; foreach (Control c23 in c.Controls) { if (c23.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox")) { data[yu] = ((TextBox)c23).Text; yu = yu + 1; } } //data[0], data[1], data[2] will contain the datas of each row. //Here you can give your insert command to the database

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups