Problem with Databinding DropDownList, XMLDataSource, XPath RRS feed

  • Question

  • User-71438059 posted


    following problem:
    I bounded two DropDownLists via two different XMLDataSources to one XML. Both XMLDataSources were initialised with a XPath argument whereby the second DataSource depend on the first one. If I perform a SelectedIndexChanged at the first DropDown I update the second DataSource with a new XPath to get a new List for my second DropDown. This works well, but NOT if i perform a SelectedIndexChanged to the Element which was initialized. An Example:

    Dropdown1: Initialized with A,B and C; A is selected
    Dropdown2: Initialized with Content of A for e.g. A1,A2,A3

    If I click B
    Dropdown gets initialized with B1,B2,B3

    If i go back to A1
    Nothing happened. No update in my DropDown2..

    I can switch between B and C and it works well, but i cannot switch back to the initialized one (A).

    My code as follows:

    <MyProg name="MyProg">
      <Parent name="A">
        <Child name="A1"></Child>
        <Child name="A2"></Child>
        <Child name="A3"></Child>
      <Parent name="B">
        <Child name="B1"></Child>
        <Child name="B2"></Child>
        <Child name="b3"></Child>
      <Parent name="C">
        <Child name="C1"></Child>
        <Child name="C2"></Child>
        <Child name="C3"></Child>


                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <asp:Label ID="Label1" runat="server" Text="Parent: "></asp:Label>
                        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
                            DataSourceID="myXML_1" DataTextField="name" DataValueField="name" 
                            Height="20px" onselectedindexchanged="DropDownList1_SelectedIndexChanged" 
                        <br />
                        <asp:XmlDataSource ID="myXML_1" runat="server" 
                            DataFile="~/App_Data/myXML.xml" XPath="/MyProg/Parent">
                        <asp:Label ID="Label2" runat="server" Text="Child: "></asp:Label>
                        <asp:DropDownList ID="DropDownList2" runat="server" 
                        DataSourceID="myXML_2" DataTextField="name" DataValueField="name" 
                            Height="20px" Width="126px" 
                        <asp:XmlDataSource ID="myXML_2" runat="server"
                            DataFile="~/App_Data/myXML.xml" XPath="/MyProg/Parent[@name='A']/Child>
                        <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged"/>

    Code behind:

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            myXML_2.XPath = "/MyProg/Parent[@name='" + DropDownList1.Text + "']/Child";

     I'm really looking forward to any help.



    Sunday, February 24, 2013 12:17 PM

All replies

  • User-134477160 posted

    What error?

    Thursday, February 28, 2013 2:39 AM
  • User-71438059 posted


    thanks for reply!

    There's no error occur. If i switch back to the entry A (which was the initalized entry) it just happens nothing! DropDownList2 don't refresh and still keep values (e.g. C1, C2, C3 instead of refreshing and containing A1, A2, A3) of the last clicked entry (in this case C).

    I cannot find an error in my code, it works well by switching all other entries instead of the initialized one (A). In a testcase, i extended the XML file with a "dummy entry" such as "<parent name="Please Select"></parent>. Then, the initialized element is not A, it's "Please Select" after this, i can switch between A, B and C and the DropDownList2 gets updated with no problems, but NOT if I switch back again to "Please Select". The expected behaviour should be an empty DropDownList2, because no childs are given to this parent.

    Again: DropDownList2 should get updated in dependence on DropDownList1. But DropDownList2 don't update if I switch back to that element which was initialized with DropDownList1. (e.g. "A" or "Please Select").

    Hopefully you understand my problem

    Thursday, March 7, 2013 6:06 AM