I have an XML Data Source:
<?xml version="1.0" encoding="utf-8" ?>
<Data>
<items>
<item id="1" text="X" />
<item id="2" text="Y" />
<item id="3" text="Z" />
</items>
</Data>
In my page I have wired this up to an asp:XmlDataSource
:
<asp:XmlDataSource runat="server" ID="data" DataFile="~/items.xml" />
And bound this to an asp:Repeater
:
<asp:Repeater runat="server" ID="list" DataSourceID="data">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li data-id="<%# XPath("item/@id") %>"><%# XPath("item/@text") %></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
But I am only getting the first item in the items list. How do I get them all?
First add an `XPath="/Data/items/item"' attribute to your XmlDataSource, then change the li elements in the ItemTemplate to:
<li data-id="<%# XPath("@id") %>"><%# XPath("@text") %></li>