Search code examples
asp.netdrop-down-menuentitydatasource

Refresh DropDownList from EntityDataSource on change of another DropDownList


What my code does is that the EntityDataSource has a Where Parameter tied to the first DropDownList and it populates the second DropDownList, but when the first DDL changes, the EntityDataSource doesn't change the values of the second DDL.

Worth mentioning this is inside a ModalPopupExtender which is inside an UpdatePanel.

Maybe there is a way in just putting all the data in the second DropDownList and filter it depending on the value of the first one... or something like that... so there's no need of refreshing the data.

<asp:DropDownList ID="PaqueteKitDropDownList" runat="server" DataSourceID="PaqueteEntityDataSource"
                DataTextField="Nombre" DataValueField="ID_Paquete" />
            <asp:EntityDataSource ID="PaqueteEntityDataSource" runat="server" ConnectionString="name=CCEntities"
                DefaultContainerName="CCEntities" EnableFlattening="False" EntitySetName="Paquetes">
            </asp:EntityDataSource>
            <br />
            <asp:Label ID="Label66" AssociatedControlID="PlanKitDropDownList" runat="server"
                Text="Plan:" />
            <asp:DropDownList ID="PlanKitDropDownList" runat="server" DataSourceID="PlanKitEntityDataSource"
                DataTextField="Duracion" DataValueField="Costo" />
            <asp:EntityDataSource ID="PlanKitEntityDataSource" runat="server" ConnectionString="name=CCEntities"
                DefaultContainerName="CCEntities" EnableFlattening="False" EntitySetName="Duracion_Plan"
                Where="it.ID_Paquete == @ID" OrderBy="it.Duracion ASC">
                <WhereParameters>
                    <asp:ControlParameter DbType="Guid" Name="ID" ControlID="PaqueteKitDropDownList"
                        PropertyName="SelectedValue" />
                </WhereParameters>
            </asp:EntityDataSource>

Solution

  • add SelectedIndexChanged Event to your first DropDownList and rebind the second one