Click here to Skip to main content
16,004,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I am trying to find out how I can save the data captured in dynamically created controls.

So what happens is on the form load I will load dynamic controls:


switch ("WhichControl")
{
case "ddl":
DropDownList ddl = new DropDownList();
ddl.ID = string.Format("ddList{0}", icounter);
ddl.DataSource = myDataSource();
ddl.DataTextField = "TextField";
ddl.DataValueField = "DataField";
ddl.ClientIDMode = System.Web.UI.ClientIDMode.Static;
ddl.DataBind();
row.Cells[1].Controls.Add(ddl);
break;
case "rb":
RadioButtonList rb = new RadioButtonList();
rb.DataSource = myDataSource();
rb.DataTextField = "TextField";
rb.DataValueField = "DataField";
rb.ID = string.Format("rList{0}", icounter);
rb.ClientIDMode = System.Web.UI.ClientIDMode.Static;
row.Cells[1].Controls.Add(rb);
break;
case "tb":
TextBox tb = new TextBox();
tb.TextMode = TextBoxMode.SingleLine;
tb.ID = string.Format("textBox{0}", icounter);
tb.ClientIDMode = System.Web.UI.ClientIDMode.Static;
row.Cells[1].Controls.Add(tb);
break;

default:
break;

}

now my question is how best can i read the options selected by the user and save it to the database.

An example would be greatly appreciated. When I try to loop through the page I can't get the controls.

Thanks,
Posted

1 solution

As much I understood from your text is you have to use 'Request.Form("Control Name Attribute value")' so get the control from form collection and than you can use these control and fetch their value to save in database.
 
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