Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build Server Controls Dynamically

Status
Not open for further replies.

AppDev76

Programmer
Jun 8, 2004
65
0
0
US
Hi,
I am building a webpage for Surveys.
I have many surveys and Each survey has many questions that change periodically.
I want to build the survey pages so that the questions are displayed dynamically by reading from a database. Thats not a problem.
The problem is that I have to create server controls for each question that will contain the answer. Answers may be text or multi choice. I have the datamodel.
All I have to do is using C# and asp.net loop through a dataReader and based on the question type create a proper server control.
The problem is that I have to declare each server control, so I can't dynamicall loop through the reader and create different controls with different names on the fly.

What options to I have?

Thanks
 
Never mind, I figured out how to do it:
System.Web.UI.WebControls.TextBox tb = new TextBox();
tb.ID = "qa"+Reader["QuestionID"].ToString();
tb.TextMode=System.Web.UI.WebControls.TextBoxMode.MultiLine;
tb.Height=50;
tb.Width=220;
Acell.Controls.Add(tb);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top