By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,818 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,818 IT Pros & Developers. It's quick & easy.

How to make dynamic controls stay?

P: n/a
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.To String), "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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
--
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of programming
you should quite and join a cult. kes
"Terry Olsen" wrote:
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.To String), "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

*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #2

P: n/a
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
--
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of programming
you should quite and join a cult. kes
"Terry Olsen" wrote:
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.To String), "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

*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.