Parent-Child DropDownList Controls
In ASP.NET Web Forms

Example 1A: Parent / Child DropDownLists Alone

This demo shows a simple parent / child DropDownList driven by SqlDataSource controls.

Select A State:
Select A Town:

Page Code

            <asp:Label runat="server" ID="lblParent" Text="Select A State: " />
            <!-- parent ddl -->
            <asp:DropDownList runat="server" ID="ddlParent" DataSourceID="sqlParentDDL" DataValueField="StateCode" DataTextField="StateName" AutoPostBack="true" />
            <!-- parent ddl is populated with a parameterless SQL query -->
            <asp:SqlDataSource runat="server" ID="sqlParentDDL" SelectCommand="GetStates" SelectCommandType="StoredProcedure" ConnectionString="<%$ ConnectionStrings:MyConnection %>" />
            <br />
            <!-- child ddl -->
            <asp:Label runat="server" ID="lblChild" Text="Select A Town: " />
            <asp:DropDownList runat="server" ID="ddlChild" DataSourceID="sqlChildDDL" DataValueField="ZIPCode" DataTextField="CityName" />
            <!-- child ddl gets its parameter value from the selected value of the parent ddl -->
                ControlParamter property values
                ControlID: The ASP.NET control that is providing the paramter's value
                Name: The parameter's name as it appears in your stored procedure / SQL query
                PropertyName: The property of the ASP.NET control that will supply the value to your parameter
            <asp:SqlDataSource runat="server" ID="sqlChildDDL" SelectCommand="GetZIPCodes" SelectCommandType="StoredProcedure" ConnectionString="<%$ ConnectionStrings:MyConnection %>">
                    <asp:ControlParameter ControlID="ddlParent" Name="StateInitials" PropertyName="SelectedValue" />