Dropdownlist bind with parameterized datasource don't keep value after postback
There is a drop down list bind with datasource -> Called This DropDownList A This datasource get another parameter from another dropdownlist -> Called This DropDownList B
Everytime DropDownList B Change the selected value, Datasource of Dropdownlist A will receive the parameter and change dropdownlist A.
Whenever DropDownlist change its index, it will cause postback and the selected value will be reset to the first index (default).
After Switching DropDownList A to use a datasource with no parameter. This problems is not occur. After DropDownList A has changed its value and postback, the recenly changed value still there.
I have tried using update panel but it still is not work either.
This is DropDownList B, Add On Type
<asp:DropDownList ID="ddlAddOnType" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" ClientIDMode="Static" CssClass="controlOrdinary"
DataSourceID="odsAddOnType" DataTextField="AddOnTypeName"
DataValueField="AddOnTypeId"
onselectedindexchanged="ddlAddOnType_SelectedIndexChanged" Width="208px">
<asp:ListItem Value="0">--Please Select--</asp:ListItem>
</asp:DropDownList>
This is datasource for dropDownlist A
<asp:ObjectDataSource ID="odsAddon" runat="server"
SelectMethod="SelectAddOnThatIsNotInCurrentPromotionWithAddOnByAddOnTypeId"
TypeName="BackOfficeLib.SupportAdmin.PromotionBinder">
<SelectParameters>
<asp:ControlParameter ControlID="ddlAddOnType" Name="pIntAddOnTypeId"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
This is dropdownlist A, when this one change the value, the page being post back suddenly and the index is reseted.
<asp:DropDownList ID="ddlAddOn"开发者_高级运维 runat="server" AppendDataBoundItems="True"
AutoPostBack="True" ClientIDMode="Static" CssClass="controlOrdinary"
DataTextField="AddOnName" DataValueField="AddOnId"
onselectedindexchanged="ddlAddOn_SelectedIndexChanged" Width="208px">
<asp:ListItem Value="0">--Please Select--</asp:ListItem>
</asp:DropDownList>
The solution i use is keeping value in hidden field by javascript, using onchange event ( change the first drop down list)
This asp.net ajax control provide some help.
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/CascadingDropDown/CascadingDropDown.aspx
精彩评论