Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7572637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:58:30+00:00 2026-05-30T15:58:30+00:00

What I am trying to do is dynamically create a bunch of dropdown lists

  • 0

What I am trying to do is dynamically create a bunch of dropdown lists and then I want to loop through them and update the database with those values, but the problem I am facing is that I create the dropdown lists, but then when I go back to loop through them they are no longer in the panel. I don’t know why but when I am debugging I have a count of 50 controls in pnlTeacherSelect right up until I press the button that calls prcChoose.

Called on Page Load

Sub prcSetTeachers()
    For Each Subject In ds.Tables("Subject").Rows
        Dim Temp As New DropDownList
        pnlTeacherSelect.Controls.Add(Temp)
        Temp.ID = "drp" & Subject.Item(0) & "s" & Child.Item(0)
    Next
End Sub

Called on Clicking a button

Sub prcChoose()
    For Each DropDownList In pnlTeacherSelect.Controls.OfType(Of DropDownList)

    'This is never executed

    Next
End Sub

Any ideas what’s causing it? Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:58:31+00:00Added an answer on May 30, 2026 at 3:58 pm

    You have to recreate all dynamically created controls on every postback(in load event at the latest).
    You also have to ensure that they get the same ID as before to trigger events and maintain ViewState.

    If you know the number of controls to create(which could be stored in ViewState) you can derive the ID from the counter variable by appending it to the control-id. Then you can recreate them with the correct ID in page’s init event.

    Recommandable readings:

    • TRULY Understanding Dynamic Controls
    • Page-Lifecycle

    Or you use one of the builtin Data-Bound Control like Repeater that do this automatically. You only have to set their DataSource and call DataBind().

    Here are answers of me on similar questions with implementations:

    • C#
    • VB.NET (+ C#)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying dynamically create an html table in PHP. Further, I want the
I'm trying to dynamically create a bunch of class properties, but each dynamic fget
I am trying to dynamically create grid.Panels and add them to my View, since
I am trying to dynamically create divs in my Rails app through javascript. However,
I want a loop to dynamically create a table up to 2 columns wide,
I am trying to dynamically create php check-boxes linked to an MSSQL-Database. The idea
I am trying to dynamically create controls and give them properties during run time.
im trying to dynamically create elements in the child window based on the values
I'm trying to dynamically create objects out of forms, but I want some reduntant
I'm trying to dynamically and programmatically create ImageButtons and add them to my Scrolling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.