A question in how to create an hierarchic dropDownLists in a formView at runtime.....

Last post 12-22-2008 8:45 AM by Danny117. 1 replies.

Sort Posts:

  • A question in how to create an hierarchic dropDownLists in a formView at runtime.....

    12-18-2008, 4:38 AM
    • Member
      6 point Member
    • avi999912
    • Member since 11-15-2008, 12:09 PM
    • Posts 199

    A question in how to create an hierarchic dropDownLists in a formView at runtime.....

    I have 3 dropDownList: 1.Countries 2.Cities 3.Streets

    I want that when i will choose a country... (autoPostback is set to true) the cities dropDownList will get the connectivity to the data.

    the problem is occuring when i'm clicking on the dropDownList of the cities(autoPostBack is set to true) and the SelectedIndexChanged is turned on.

    On the SelectedIndexChanged method of the cities dropDownList... i'm trying to set the dataSource property of the streets.

    but it always stays on the selectedIndex of 0 on the 'cities' dropDownList.

     my code: (the DropDownListNew_DataBinding method is called from a class that implements ITemplate)

    Private Sub DropDownListNew_DataBinding(ByVal sender As Object, ByVal e As EventArgs)

    ......

    .....

    Case "StateCode"

    _DropDL.DataSource = DA_Ado_States.GetData_ValueAndName()

    _DropDL.DataTextField = "StateName"

    _DropDL.DataValueField = "StateCode"

    AddHandler _DropDL.SelectedIndexChanged, AddressOf DropDownListNew_StatesSelectedIndexChanged

    Case "CityCode"

    _DropDL.DataTextField = "CityName"

    _DropDL.DataValueField = "CityCode"

    AddHandler _DropDL.SelectedIndexChanged, AddressOf DropDownListNew_CitiesSelectedIndexChanged

    Case "StreetCode"

    _DropDL.DataTextField = "StreetName"

    _DropDL.DataValueField = "StreetCode"

    End Select

    _DropDL.ForeColor = Drawing.Color.Black

    _DropDL.Font.Name = "arial"

    _DropDL.Font.Size = 8

    _DropDL.Width = 66

    _DropDL.AutoPostBack = "true"

     

     

    Private Sub DropDownListNew_PreRender(ByVal sender As Object, ByVal e As EventArgs)

    Dim _DropDL As DropDownList = CType(sender, DropDownList)

    _DropDL.Items.Insert(0, "None")

    ' _DropDL.SelectedIndex = 0

    End Sub

    Private Sub DropDownListNew_StatesSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

    Dim _DropDL As DropDownList = CType(sender, DropDownList)

    Dim _DropDL_Cities As DropDownList = DirectCast(_FormViewReference.FindControl("New_CityCode"), DropDownList)

    _DropDL_Cities.DataSource = DA_Ado_Cities.GetData_ValueAndName(Val(_DropDL.SelectedValue))

    _DropDL_Cities.DataBind()

    End Sub

    Private Sub DropDownListNew_CitiesSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

    Dim _DropDL As DropDownList = CType(sender, DropDownList)

    Dim _DropDL_Streets As DropDownList = DirectCast(_FormViewReference.FindControl("New_StreetCode"), DropDownList)

    _DropDL_Streets.DataSource = DA_Ado_Streets.GetData_ValueAndName(Val(_DropDL.SelectedValue))

    _DropDL_Streets.DataBind()

    End Sub

  • Re: A question in how to create an hierarchic dropDownLists in a formView at runtime.....

    12-22-2008, 8:45 AM
    Answer
    • Star
      10,558 point Star
    • Danny117
    • Member since 12-16-2008, 2:30 PM
    • Royal Oak Michigan USA
    • Posts 1,837

    Without looking at your code you should maybe possibly watch the cascading drop down list video http://www.asp.net/learn/ajax-videos/video-77.aspx.  You'll end up with an application thats too cool.  If your having trouble with the data access watch this video.  http://www.asp.net/learn/videos/video-49.aspx  It's a favorite of mine.

     

     

    Good Luck



Page 1 of 1 (2 items)