I have two cascading dropdownlists. When the first dropdownlist is selected, the data source for the second is updated.
This works the first time through the page, but if the first dropdown list is changed, then the values in the second dropdown list are all undefined.
ASPX code:
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
Data Set:
<ej:DropDownList ID="DatasetDropDownList1" runat="server" WatermarkText="Select A DataSet">
<Items>
<ej:DropDownListItem runat="server" Text="Circuits" Value="Circuits" />
<ej:DropDownListItem runat="server" Text="Deficiencies" Value="Deficiencies" />
</Items>
</ej:DropDownList>
<br/>
Facility:
<ej:DropDownList ID="FacilityDropDownList" runat="server" WatermarkText="Select A Facility" DataTextField="FACILITYID"
DataValueField="FACILITYID">
</ej:DropDownList>
<asp:SqlDataSource ID="FacilityDropDownDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:EC_WEB %>"
ProviderName="<%$ ConnectionStrings:EC_WEB.ProviderName %>"
SelectCommand="SELECT ID AS FACILITYID FROM [\\Celery\published\web_test].WebFacilities WHERE (WEB_AUTH_KEY = ?)">
<SelectParameters>
<asp:SessionParameter Name="WEB_AUTH_KEY" SessionField="WebKey" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
VB Code:
Private Sub DatasetDropDownList1_ValueSelect(sender As Object, e As DropdownListEventArgs) Handles DatasetDropDownList1.ValueSelect
If e.Value = "Circuits" Then
Dim data As DataView = DirectCast(FacilityDropDownDataSource.[Select](New DataSourceSelectArguments()), DataView)
Dim dt As DataTable = data.Table
FacilityDropDownList.DataSource = dt
FacilityDropDownList.DataBind()
ElseIf e.Value = "Deficiencies" Then
Dim data As DataView = DirectCast(FacilityDropDownDataSource.[Select](New DataSourceSelectArguments()), DataView)
Dim dt As DataTable = data.Table
Dim workRow As DataRow = dt.NewRow()
workRow(0) = "-SELECT ALL-"
dt.Rows.InsertAt(workRow, 0)
FacilityDropDownList.DataSource = dt
FacilityDropDownList.DataBind()
End If
End Sub
Attachment:
Dropdownlist__Undefined_4ddf7276.zip