How to make dynamic controls stay?

T

Terry Olsen

I want to have a series of DropDownLists appear. On PageLoad, the first
list is created. When I make a choice, a 2nd list is created, data
loaded depending on the choice from the first list, and so on...

However, when the choice is made on the 2nd list, it goes away and only
the 1st list remains (because it's being created on PageLoad).

Here's the code. Hope someone can help:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
AddDDL(GetColumnNames, "ddlCol")
End If
End Sub

Private Sub AddDDL(ByVal data As ArrayList, ByVal name As String)
Dim MyDDL As New DropDownList
With MyDDL
.DataSource = data
.DataBind()
.ID = name
.AutoPostBack = True
End With
PlaceHolder1.Controls.Add(MyDDL)
AddHandler MyDDL.SelectedIndexChanged, AddressOf
DDL_SelectedIndexChanged
End Sub

Private Sub DDL_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Dim MyDDL As DropDownList = CType(sender, DropDownList)
If InStr(MyDDL.ID, "Col") Then
Dim MyAL As New ArrayList
With MyAL
.Add("=") : .Add("<>") : .Add(">") : .Add("<")
End With
AddDDL(MyAL, "ddlExp")
AddDDL(GetDistinctFromColumn(MyDDL.SelectedItem.ToString), "ddlDat")
ElseIf InStr(MyDDL.ID, "Exp") Then
'Don't do anything, just making a choice.
ElseIf InStr(MyDDL.ID, "Dat") Then
'Code here to add another column list
End If
End Sub
 
G

Guest

I believe dynamic controls need to be recreated on each load. That is one of
their draw backs. set some You could create a default value for list 2 and if
its the default do not create the list. If is is a set value re-create the
list and set th eselected with the value.
Another way to do this is to create the controls staticly but keep to
ddl.visible = false until needed. when needed populate the control and with
viewstate = true, the values should stay.
hope this helps
thanks
kes
 

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,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top