0

I have a repeater with an xmlDataSource. What I need is very simple, but i can't make it happen. Using this xml file I want to display all the nodes from the project "ProjectOne".

<?xml version="1.0" encoding="utf-8" ?>
<projects>
<project name="ProjectOne">
    <description>this is the description</description>
    <image>image1</image>
    <image>image2</image>
    <image>image3</image>
</project>
<project name="ProjectTwo">
    <description>this is the description</description>
    <image>image1</image>
</project>

I'm using this repeater with an xmlDataSource. But it only shows the first image node (image1) instead of showing all the nodes (image1 + image2 + image3)

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1"  >
<ItemTemplate>
    <div>
        <img src='<%#XPath("image")%>' alt='test' />
    </div>
</ItemTemplate>
</asp:Repeater>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="App_Data/ProjectsPosta.xml" XPath="projects/project[@name='ProyectOne'] " />

I want to do it without touching the .cs if it's possible
Any idea??
Thanks

gpergo
  • 155
  • 1
  • 1
  • 5

1 Answers1

1

I don't know much about ASP repeater, but knowing XPath, here's what I would try:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1"  >
  <ItemTemplate>
    <div>
        <img src='<%#XPath(".")%>' alt='test' />
    </div>
  </ItemTemplate>
</asp:Repeater>
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
      DataFile="App_Data/ProjectsPosta.xml"
      XPath="projects/project[@name='ProjectOne']/image" />

Note the change of 'ProyectOne' to 'ProjectOne'.

LarsH
  • 27,481
  • 8
  • 94
  • 152