Creating control dynamically

  • Thread starter supak C via .NET 247
  • Start date
S

supak C via .NET 247

Dear All,

I need help with the control

In my database will store page detail including field name and type of control to display in the page such as

Page 1

Name , textbox
Lastname , textbox
Age , Dropdown , tblCustomerAge (this is data source)

The problem is I need to create the control in the web page exactly what I can retrieve data from the database.

Anyone has any idea ?
 
M

Mohamed El Ashmawy

You could use the Page_Load event for that.
You would read the needed controls data from the database. for example
"Name , textbox ".
Then you would create a textbox dynamcially with the saved specifications.
for example, System.Web.UI.WebControls.TextBox
mytextbox = new System.Web.UI.WebControls.TextBox();
mytextbox.Text = "Name";

Then you would add the control to your form
form.Controls.Add(mytextbox);


You would need to have form pointing to the form in the page at the
beginning.
The definition of form would be System.Web.UI.HtmlControls.HtmlForm form;
and the initilization would be form = (HtmlForm) this.FindControl("Form1");

I hope this answers your question.

Please send me back if there is something vague.
Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top