Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 18th, 2008, 03:43 PM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default how can selectedvalue of DDL make other DDL visibl

Hi,

i generate 3 dropdownlists. I have to do that with code-behind because i never know in advance how many i need. The amount comes from a database.
Dropdownlist 2 is not visible, the others are visible.
When the selectedvalue of dropdownlist 1 equals "b" then dropdownlist 3 must be visible.

I can do everything except: setting DDL3 visible when selectedvalue of DDL1 equals "b".

Here the code:

Friend dds As New List(Of DropDownList)

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim i As Integer
        Dim lit As LiteralControl
        Dim z1, z2, z3 As ListItem
        For i = 1 To 3
            If Not IsPostBack Then
                Dim dd As New DropDownList
                dd.AutoPostBack = True
                dd.ID = i
                z1 = New ListItem("a", "a")
                z2 = New ListItem("b", "b")
                z3 = New ListItem("c", "c")
                dd.Items.Add(z1)
                dd.Items.Add(z2)
                dd.Items.Add(z3)
                Session(dd.ID) = dd.ID
                If i = 3 Then dd.Visible = False
                dds.Add(dd)
                Session("dds") = dds
            Else
                dds = CType(Session("dds"), List(Of DropDownList))
            End If
        Next

        For Each d As DropDownList In dds
            form1.Controls.Add(d)
            lit = New LiteralControl("<br>")
            form1.Controls.Add(lit)
            AddHandler d.SelectedIndexChanged, AddressOf dropd
        Next
    End Sub

    Protected Sub dropd(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim dd As DropDownList = CType(sender, DropDownList)
        If dd.ID = 1 And dd.SelectedValue = "b" Then
           [u] 'dd with ID=3 must be visible: how to do that?</u>
        End If
    End Sub
End Class

Thanks
H.



 
Old May 18th, 2008, 04:25 PM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Little mistake: it's DDL 3 which is invisible and not DDL 2.

 
Old May 19th, 2008, 10:05 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found it:
 CType(FindControl("3"), DropDownList).Visible = False

 
Old May 19th, 2008, 10:46 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You could save the DDLs into a list as you create then. Then you can loop through the list and look for the one you want to change.

You say that the number of DDLs is unknown (coming from a database). Will the values in the DDLs come from the database too? If so, how are you going to determine what value in one DDL should make another visible?

-Peter
compiledthoughts.com
 
Old May 20th, 2008, 04:38 PM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your suggestion.
The id of the ddl which affects others is also in a table.






Similar Threads
Thread Thread Starter Forum Replies Last Post
DDL Custom Validator AspNetGuy BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 6th, 2008 05:17 PM
DDL error cmw231 ASP.NET 2.0 Basics 2 July 17th, 2006 08:07 AM
ddl response.redirect and passing value dorothee ASP.NET 1.0 and 1.1 Basics 0 June 11th, 2004 03:14 AM
Displaying a passed value in a databound DDL acorbo ASP.NET 1.0 and 1.1 Professional 1 May 19th, 2004 04:56 PM
select a value from ddl at page load KevinO ASP.NET 1.0 and 1.1 Basics 5 December 29th, 2003 09:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.