views:

32

answers:

1

I have an XML file structured as follows:

<Levels>
  <Level Code="T" Text="Test">
    <SubLevels>
      <SubLevel Type="9" Text="Nine"/>
      <SubLevel Type="8" Text="Eight"/>
      <SubLevel Type="7" Text="Seven"/>
      <SubLevel Type="6" Text="Six"/>
    </SubLevels>
  </Level>
  <Level Code="T2" Text="Test 2">
    <SubLevels>
      <SubLevel Type="1" Text="One"/>
      <SubLevel Type="2" Text="Two"/>
    </SubLevels>
  </Level>
</Levels>

What I want is two drop down lists, one linked to /Levels/Level and one to the SubLevels for the selected level. Currently, I have the main one bound as follows:

 <asp:XmlDataSource ID="XmlLevelInfo" runat="server" DataFile="~/Levels.xml">
 </asp:XmlDataSource>
 <asp:DropDownList ID="cboLevelFilter" runat="server" 
                      DataSourceID="XmlLevelInfo" DataTextField="Text" DataValueField="Code">
 </asp:DropDownList>

This works fine, but I can’t work out how to link the Sub Levels to the second drop down list. Is this possible using data binding?

A: 

I would expect that the XmlDataSource for your second drop-down would need to have it's XPath varied on SelectedItemChanged of the first.

Such that it's XPath might look like: //Level[@Code = '<CODE VALUE FROM SELECTED ITEM>']//SubLevel

You'd probably also want to initially just bind it with all SubLevels such that the XPath might look like: //SubLevel

Then it'll take a little extra effort to AJAX-ify it all for a nice experience... (Don't forget to set AutoPostBack to true on the first drop-down!)

Reddog