Visual Studio .NET - dynamic dropdownlist control

toma hawk posted at 24-Aug-04 12:34
Hi 

    in my code for aspx i create a dropdown list dynamically and add it to a place holder control ,but upon postback i am unable to find the control or find the selected value in the dropbox so that i can create another dropbox with some other values.Here is the code 
 how do i solve this issue ? i tried adding the control again after postback

Please help 


---------------------------------------------------------
Dim dd1 As DropDownList = New DropDownList
Dim dd2 As DropDownList = New DropDownList

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Me.IsPostBack = True Then
           ' PlaceHolder1.Controls.Add(dd1)
           ' Dim dd2 As DropDownList = CType(Me.Placeholder1.FindControl("dd1"), DropDownList)
            If dd1.SelectedIndex = 2 Then
                dd2.Items.Add("None")
                dd2.Items.Add("B1")
                dd2.Items.Add("B2")
                PlaceHolder1.Controls.Add(dd2)
            End If
        Else
            dd1.Items.Add("None")
            dd1.Items.Add("A1")
            dd1.Items.Add("A2")
            dd1.AutoPostBack = True
            dd1.EnableViewState = False
            PlaceHolder1.Controls.Add(dd1)

        End If
    End Sub
-----------------------------------------------------------------------

Click here to sign in and reply. You could earn money via our message board contest just for being helpful.
  dynamic dropdownlist control - toma hawk  24-Aug-04 12:34 12:34:04 AM
      Dynamically created ASP NET controls - Peter Bromberg  24-Aug-04 08:25 8:25:27 AM
          Recreating dynamically created controls - blake miller  21-Sep-04 04:42 4:42:14 AM
              Exactly - Peter Bromberg  21-Sep-04 02:08 2:08:58 PM
                  ? - blake miller  21-Sep-04 05:19 5:19:36 PM
                      OK let's back up for a second - Peter Bromberg  21-Sep-04 05:49 5:49:57 PM
                          Theory - blake miller  21-Sep-04 08:18 8:18:59 PM
                              Solution - blake miller  21-Sep-04 10:16 10:16:12 PM
View Posts

  

Search

search



Purchase