I have some cascading dropdowns. DD2 and DD3 are in update panels. DD1 triggers DD2 which then triggers DD3. When they pick DD1, my selected index is correct. When they pick DD2, DD1 and DD2 selected index is correct. When they pick DD3, I lose the selected index in DD2. If I have DD3 set to autopost back, the value blanks out in the DD2. IF I have DD3 NOT set to auto post back, DD2 remains selected properly but when they hit the save button DD2's selected index is -1 but DD1 and DD3 are fine. Code below.
<table> <tr> <td class="label" align="right">Asset Class:</td> <td> <ig:WebDropDown runat="server" ID="ddAssetClass" Width="250px" DisplayMode="DropDownList" EnableViewState="false" Button-ImageUrl="~/images/igdd_DropDownButton.png" CssClass="normalClass" CurrentValue="" DropDownContainerHeight="200px"> <ClientEvents /> <AutoPostBackFlags SelectionChanged="On" /> </ig:WebDropDown> </td> </tr> <tr> <td class="label" align="right">Asset Sub Class:</td> <td> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddAssetClass" /> </Triggers> <ContentTemplate> <ig:WebDropDown runat="server" ID="ddSubClass" Width="250px" DisplayMode="DropDownList" EnableViewState="false" Button-ImageUrl="~/images/igdd_DropDownButton.png" CssClass="normalClass" CurrentValue="" DropDownContainerHeight="200px"> <ClientEvents /> <AutoPostBackFlags SelectionChanged="On" /> </ig:WebDropDown> </ContentTemplate> </asp:UpdatePanel> </td> </tr> <tr> <td class="label" align="right">Asset Nomanclature:</td> <td> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddSubClass" /> </Triggers> <ContentTemplate> <ig:WebDropDown runat="server" ID="ddNomanclature" Width="250px" DisplayMode="DropDownList" EnableViewState="false" Button-ImageUrl="~/images/igdd_DropDownButton.png" CssClass="normalClass" CurrentValue="" DropDownContainerHeight="200px"> </ig:WebDropDown> </ContentTemplate> </asp:UpdatePanel> </td> </tr></table>
IN PAGE LOAD ......... ' fill asset class ddddAssetClass.DataSource = objLogBook.ReturnAssetClassList(WorkCenterID.Value)ddAssetClass.TextField = "AssetName"ddAssetClass.ValueField = "AssetClassID"' before databinding, grab the item they had selectediItemIndex = ddAssetClass.SelectedItemIndexddAssetClass.DataBind()
If (iItemIndex > 0) Then ddAssetClass.SelectedItemIndex = iItemIndex strAssetClassValue = ddAssetClass.SelectedValueEnd If
'async panel asset sub dropdownIf strAssetClassValue > "" Then ddSubClass.DataSource = objLogBook.ReturnAssetSubList(strAssetClassValue) ddSubClass.TextField = "AssetName" ddSubClass.ValueField = "AssetClassID" ' before databinding, grab the item they had selected iItemIndex2 = ddSubClass.SelectedItemIndex ddSubClass.DataBind()End If
If (iItemIndex2 > 0) Then ddSubClass.SelectedItemIndex = iItemIndex2 strSubClassValue = ddSubClass.SelectedValueEnd If
'async panel asset nomanclature dropdownIf strSubClassValue > "" Then ddNomanclature.DataSource = objLogBook.ReturnAssetSubList(strSubClassValue) ddNomanclature.TextField = "AssetName" ddNomanclature.ValueField = "AssetClassID" ' before databinding, grab the item they had selected iItemIndex3 = ddNomanclature.SelectedItemIndex ddNomanclature.DataBind()End If
If (iItemIndex3 > 0) Then ddSubClass.SelectedItemIndex = iItemIndex3End If
Hello,according to your code, you need to cascade 3 drop downs and store all the of the selected values after a postback. To do so, you need to enable the viewstate of the controls (EnableViewState = "true"). At the code-behind, I see that you are rebinding the next dropdown if the current drop down slected index is greater than 0. Insead of doing so, why don't you handle the SelectionChanged event and then rebind the drop downs. I believe it will make the things much easier for you. Try the following code:Protected Overrides Sub OnInit(e As EventArgs) MyBase.OnInit(e) ddAssetClass.SelectionChanged += New DropDownSelectionChangedEventHandler(AddressOf ddAssetClass_SelectionChanged) ddSubClass.SelectionChanged += New DropDownSelectionChangedEventHandler(AddressOf ddSubClass_SelectionChanged) ddNomanclature.SelectionChanged += New DropDownSelectionChangedEventHandler(AddressOf ddNomanclature_SelectionChanged)End SubProtected Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then ddAssetClass.DataSource = objLogBook.ReturnAssetClassList(WorkCenterID.Value) ddAssetClass.TextField = "AssetName" ddAssetClass.ValueField = "AssetClassID" ddAssetClass.DataBind() End IfEnd SubPrivate Sub ddNomanclature_SelectionChanged(sender As Object, e As DropDownSelectionChangedEventArgs)End SubPrivate Sub ddSubClass_SelectionChanged(sender As Object, e As DropDownSelectionChangedEventArgs) ddNomanclature.DataSource = objLogBook.ReturnAssetSubList(ddSubClass.SelectedValue) ddNomanclature.TextField = "AssetName" ddNomanclature.ValueField = "AssetClassID" ddNomanclature.DataBind()End SubPrivate Sub ddAssetClass_SelectionChanged(sender As Object, e As DropDownSelectionChangedEventArgs) ddSubClass.DataSource = objLogBook.ReturnAssetSubList(ddAssetClass.SelectedValue) ddSubClass.TextField = "AssetName" ddSubClass.ValueField = "AssetClassID" ddSubClass.DataBind()End SubRegards,Nikolai Dimitrov
I tried this out and it seems to make it worse.
Change value of 1st one and it fills the 2nd one just fine.
Change value of the 2nd one, and it runs the code to fill the 2nd one again (why??) which causes 2nd one to blank out and it does not fill the 3rd one.
Hi,
I am just following up on this forum post.
Please let me know if you require further assistance.
Sincerely, Matt Developer Support Engineer