I have 2 drop-down lists. One is populated manually. The other I would like to bind to a different table depending on the value selected in the first.
Protected Sub ContactType_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ContactType.SelectedIndexChanged
Dim dc As New DataClassesDataContext()
If ContactType.SelectedItem.Text = "Company" Then
ContactRelationship.DataSource = dc.CompanyTypes
ContactRelationship.DataTextField = "CompanyType"
ContactRelationship.DataValueField = "CompanyTypeID"
ContactRelationship.DataBind()
ElseIf ContactType.SelectedItem.Text = "Employee" Then
ContactRelationship.DataSource = dc.EmployeeTypes
ContactRelationship.DataTextField = "EmployeeType"
ContactRelationship.DataValueField = "EmployeeTypeID"
ContactRelationship.DataBind()
End If
End Sub
<asp:DropDownList ID="ContactType" runat="server" Width="200px" AutoPostBack="True">
<asp:ListItem Text="Company">
<asp:ListItem Text="Employee">
<asp:ListItem Text="Emergency Contact">
<asp:ListItem Text="Associates">
<asp:DropDownList ID="ContactRelationship" runat="server" Width="200px">
I know the code is barbaric, I'll clean it up after I find the solution.
I'm using asp.net 4.0, Linq to SQL, and Sql Server express 2008r2.
I'm getting an error after I try to change value in ddl1. It seem to me that ddl2 will not bind to another table until it is somehow unbound?
All I really need is a push in the right direction. Thank you for your help.