Dynamic control add in form and finally store in to database
-
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
-
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
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.
-
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
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