Lost selection from dropdownlist after postback???
-
I have 2 dropdownlists on a formview. The list of the second one (ddl_2) is depend on the selected value of the first one (ddl_1). I use a client callback function (GetDDL2List) on event OnChange to retrieve the list for the second one. After I selected for a value from the first one list of the second come out correctly. After I make a selection from the second one and submit (post back) the form, however, the selection of the second one is lost. <asp:DropDownList ID="ddl_1" Runat="server" DataSourceID="ods_1" DataValueField="cde_item" DataTextField="txt_item" OnDataBound="ddl_1_DataBound" onchange="GetDDL2List(this.value, 'ddl'); " /> <asp:ObjectDataSource ID="ods_1" Runat="server" TypeName="Proj1.Test" SelectMethod="GetList1" </asp:ObjectDataSource> <asp:DropDownList ID="ddl_2" Runat="server" DataSourceID="ods_2" DataValueField="cde_tem" DataTextField="txt_item" OnDataBound="ddl_2_DataBound" /> <asp:ObjectDataSource ID="ods_2" Runat="server" TypeName="Proj1.Test" SelectMethod="GetList2" <SelectParameters> <asp:ControlParameter Name="sGroup" ControlID="ddl_1" DefaultValue="-1" Type="string" /> </SelectParameters> </asp:ObjectDataSource>
-
I have 2 dropdownlists on a formview. The list of the second one (ddl_2) is depend on the selected value of the first one (ddl_1). I use a client callback function (GetDDL2List) on event OnChange to retrieve the list for the second one. After I selected for a value from the first one list of the second come out correctly. After I make a selection from the second one and submit (post back) the form, however, the selection of the second one is lost. <asp:DropDownList ID="ddl_1" Runat="server" DataSourceID="ods_1" DataValueField="cde_item" DataTextField="txt_item" OnDataBound="ddl_1_DataBound" onchange="GetDDL2List(this.value, 'ddl'); " /> <asp:ObjectDataSource ID="ods_1" Runat="server" TypeName="Proj1.Test" SelectMethod="GetList1" </asp:ObjectDataSource> <asp:DropDownList ID="ddl_2" Runat="server" DataSourceID="ods_2" DataValueField="cde_tem" DataTextField="txt_item" OnDataBound="ddl_2_DataBound" /> <asp:ObjectDataSource ID="ods_2" Runat="server" TypeName="Proj1.Test" SelectMethod="GetList2" <SelectParameters> <asp:ControlParameter Name="sGroup" ControlID="ddl_1" DefaultValue="-1" Type="string" /> </SelectParameters> </asp:ObjectDataSource>
-
Verify that when you bind your DropDownLists that you are only doing it if !Page.IsPostBack