Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1495
Cascading Web Drop Downs
posted

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 dd
ddAssetClass.DataSource = objLogBook.ReturnAssetClassList(WorkCenterID.Value)
ddAssetClass.TextField = "AssetName"
ddAssetClass.ValueField = "AssetClassID"
' before databinding, grab the item they had selected
iItemIndex = ddAssetClass.SelectedItemIndex
ddAssetClass.DataBind()

If (iItemIndex > 0) Then
    ddAssetClass.SelectedItemIndex = iItemIndex
    strAssetClassValue = ddAssetClass.SelectedValue
End If

'async panel asset sub dropdown
If 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.SelectedValue
End If

'async panel asset nomanclature dropdown
If 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 = iItemIndex3
End If

Parents
No Data
Reply
  • 695
    posted

    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 Sub

    Protected 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 If
    End Sub

    Private Sub ddNomanclature_SelectionChanged(sender As Object, e As DropDownSelectionChangedEventArgs)

    End Sub

    Private Sub ddSubClass_SelectionChanged(sender As Object, e As DropDownSelectionChangedEventArgs)
        ddNomanclature.DataSource = objLogBook.ReturnAssetSubList(ddSubClass.SelectedValue)
        ddNomanclature.TextField = "AssetName"
        ddNomanclature.ValueField = "AssetClassID"
        ddNomanclature.DataBind()
    End Sub

    Private Sub ddAssetClass_SelectionChanged(sender As Object, e As DropDownSelectionChangedEventArgs)
        ddSubClass.DataSource = objLogBook.ReturnAssetSubList(ddAssetClass.SelectedValue)
        ddSubClass.TextField = "AssetName"
        ddSubClass.ValueField = "AssetClassID"
        ddSubClass.DataBind()
    End Sub

    Regards,
    Nikolai Dimitrov

Children