Results 1 to 3 of 3

Thread: Dynamic Control creation?

  1. #1

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Dynamic Control creation?

    Hi,

    I'm pretty new to asp.net and kind of been thrown in at the deepend.

    I'd like to know if it's possible to dynamically create webform controls at run time? In this case a user enters a number and that number of dropdownlists are created on the page.

    Any help appreciated.

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Sure, anything is possible with asp.net

    Code:
    private void Button1_Click(object sender, System.EventArgs e) {
        for(int i = 0; i < int.Parse(TextBox1.Text); i++) {
            this.FindControl("Form1").Controls.Add(new DropDownList());
        }		
    }

  3. #3

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    Thanks a lot for your reply. Got it working ok. Turns out now that there will be in the region of 100-120 drop down boxes so now just to make sure they're all laid out nicely

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width