How to make dynamic controls stay?  
Author Message
BladeMaster





PostPosted: Fri Jul 15 14:49:02 CDT 2005 Top

ASP.Net >> How to make dynamic controls stay?

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

*** Sent via Developersdex http://www.hide-link.com/ ***

Web Programming146  
 
 
WebBuilder451





PostPosted: Fri Jul 15 14:49:02 CDT 2005 Top

ASP.Net >> How to make dynamic controls stay? 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




> 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
>
> *** Sent via Developersdex http://www.developersdex.com ***
>