Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2007, 01:43 PM
Registered User
 
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating Controls At Run-Time

What's the best approach for creating controls at run-time. I am trying to create a variable number of dropdowns. The number required, the labels and the data source are only known at run-time and created in some separate vb code. Does anyone know how to do this? Or know of any good examples? Even a few keywords to search the web for would help.

Thanks for any help.

Rob

 
Old July 25th, 2007, 01:38 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use the following code:
   Label lbl = new Label();
   lbl.Text = "test";

   this.form1.Controls.Add(lbl);

Note that if you want to use this labes out side the creating function you should define it as a global verible

Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
 
Old July 25th, 2007, 04:57 AM
Authorized User
 
Join Date: Apr 2006
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via AIM to anujrathi Send a message via MSN to anujrathi Send a message via Yahoo to anujrathi
Default

Hi Rob,
suppose u hav to add some Label to a placeholder control:
private void CtreateNew(int iCount)
{
Label lblToAdd= new Label ();
lblToAdd.ID = "lbl" + iCount;
plshSelect.Controls.Add(lblToAdd); // Placeholder to add
}

Regards,
Anuj





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating run time controls, manish_kaushik ASP.NET 2.0 Basics 1 February 10th, 2007 04:11 PM
Create Controls in Run Time Fredu Access 3 January 8th, 2005 10:03 AM
Copying controls at run time aspadda Excel VBA 0 November 12th, 2003 01:07 PM
Adding controls at run-time !! kishore_peddi C# 0 October 13th, 2003 06:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.