Referencing Dynamically Created Controls in PlaceHolder

  • Thread starter Leona Vo via .NET 247
  • Start date
L

Leona Vo via .NET 247

I was able to create dropdownlist dynamically and place them inplaceholder as follows:

for i = 0 to 5
Dim ShowDropDownList = New DropDownList
ShowDropDownList.Visible = True
ShowDropDownList.ID = "DropDownList" & i
ShowDropDownList.Style("position") = "absolute"
ShowDropDownList.Style("left") = "248px"
ShowDropDownList.Style("top") = j & "px"
PlaceHolder1.Controls.Add(ShowDropDownList)
next

I want to retrieve values from the dynamically created controls,in this case the dropdownlist controls. However, when the userclick on the submit button, the program no longer see thecontrols in PlaceHolder1. It appears that I have a view stateproblem, but I can't figure out a way around it. This is how Ireference the code and this is where I receive the error.

for i = 0 to 5
strWhereClause +=CType(PlaceHolder1.FindControl("DropDownList" & i),DropDownList).SelectedValue
next

Please help someone.
 

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top