Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2005

Tip: Looking for answers? Try searching our database.

How to make dynamic controls stay?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Terry Olsen - 15 Jul 2005 20:21 GMT
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
WebBuilder451 - 15 Jul 2005 20:49 GMT
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
Signature

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
[quoted text clipped - 43 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.