Click here to Skip to main content
15,944,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
i have 2 DropdownList in my asp project and the first one is populated from SQL DB and the other one is populated from SQL DB but based on the selected value from the first one .
the problem is when i select the value from the second DropdonList and click on save i got nothing , the selected item is nothing

Note : both of DropdownList are Located into Repeater Control

What I have tried:

VB
To Populate DropDownList i use the following :
Dim dr As System.Data.SqlClient.SqlDataReader
                        Dim iListItem8 As New ListItem
                        iListItem8.Value = -1
                        iListItem8.Text = ""
                        cmbFinish.Items.Add((iListItem8))
                        dr = FinishType.AS_GetAllFinishType("ID")
                        While dr.Read
                            Dim iListItem88 As New ListItem
                            iListItem88.Value = dr("ID")
                            iListItem88.Text = dr("FinishCode") & " - " & dr("Description")
                            cmbFinish.Items.Add((iListItem88))
                        End While
                        dr.Close()


'*************************************************
 Protected Sub cmbFinish_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
         Dim cmbFinish As DropDownList = CType(sender, DropDownList)
        Dim currentRow As RepeaterItem = CType(cmbFinish.NamingContainer, RepeaterItem)
        Dim cmbColor As DropDownList = CType(currentRow.FindControl("cmbColor"), DropDownList)
        If ((Not (cmbFinish) Is Nothing) AndAlso ((cmbFinish.SelectedIndex > 0) AndAlso (Not (cmbColor) Is Nothing))) Then
            Dim FinishID As String = cmbFinish.SelectedValue
            Dim dr As System.Data.SqlClient.SqlDataReader
            Dim iListItem9 As New ListItem
            iListItem9.Value = -1
            iListItem9.Text = ""
            cmbColor.Items.Add((iListItem9))
            dr = FinishColor.AS_GetAllFinishColorByFinishTypeID(FinishID)
            While dr.Read
                Dim iListItem99 As New ListItem
                iListItem99.Value = dr("ID")
                iListItem99.Text = ("ColorCode") & " - " & dr("Description")
                cmbColor.Items.Add((iListItem99))
            End While
            dr.Close()
        ElseIf (Not (cmbColor) Is Nothing) Then
            cmbColor.Items.Clear()
        End If

    End Sub
Posted
Updated 2-Aug-17 19:54pm

1 solution

Check this they give clear example for you.
Using CascadingDropDown with a Database (VB) | Microsoft Docs[^]
 
Share this answer
 
Comments
DEV-MOK 3-Aug-17 2:08am    
hias i mentioned before in my code , i already know how to populate the DropdonList based on selected from one of them but the problem is when i select the value from the second one (where the values there is populated based on the selected from the first one) and click Save , the second dropdownlist is loosing the data and the selected item

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900