Greetings!
I have some XML like this:
<Root>
<MainSection>
<SomeNode>Some Node Value</SomeNode>
<SomeOtherNode>Some Other Node Value</SomeOtherNode>
<Areas>
<Area someattribute="aaa" name="Alpha" value="0" />
<Area someattribute="bbb" name="Beta" value="1" />
<Area someattribute="ddd" name="Delta" value="2" />
</Areas>
</MainSection>
</Root>
I have a FormView on my web form in which many of the values are bound. I'd like to bind the Areas child nodes to a DropDownList like so:
<asp:FormView ID="MyFormView" runat="server" DataSourceID="MyXmlDataSource">
<ItemTemplate>
<h1><%# XPath("SomeNode")%></h1>
<asp:Label ID="MyLabel" runat="server" AssociatedControlID="MyDdl" Text='<%# XPath("SomeOtherNode")%>' />
<asp:DropDownList ID="MyDdl" runat="server" DataSource='<%# XPathSelect("Areas/*") %>' DataTextField="name" DataValueField="value"></asp:DropDownList>
</ItemTemplate>
</asp:FormView>
<asp:XmlDataSource ID="MyXmlDataSource" runat="server" XPath="Root/MainSection" />
Unfortunately, instead of seeing the data that I'd expect in the dropdown list, I see 3 entries with "Area" as the text and no values.
I know that my XML is ok because for testing purposes, I tried throwing a Repeater control on the page like so:
<asp:Repeater ID="MyRepeater" runat="server" DataSource='<%# XPathSelect("Areas/*") %>'>
<ItemTemplate>
<%# XPath("@name") %> - <%# XPath("@value") %><br />
</ItemTemplate>
</asp:Repeater>
And that worked fine.
Is there something that I'm doing wrong when binding to the dropdown list, perhaps with the DataTextField and DataValueField properties?