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 SubPrivate 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 SubPrivate 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