Question

I am trying to build a product detail page menu navigation and want to only show the navigation items for products that are in the same category.

The data is maintained in two different XML files. One containing the current product data, and one containing the navigation information. Both contain "category" as an element.

I would like to use another XmlDataSource and then pass in the current products category from the parent container, accessible using XPath("category"), to the XPath attribute to filter the values.

I would then pass this filtered data source to a repeater for rendering.

<%-- get the current product XML --%>
<asp:XmlDataSource ID="productDS" runat="server" XPath="/product" DataFile="~/App_Theme/project/products/poduct1.xml"/> 
<asp:DataList ID="product" DataSourceID="productDS" runat="server">
<ItemTemplate>
     <%-- 
        get the navigation XML and filter the nodes to only show the navItems with the current product category
     --%>       
     <asp:XmlDataSource ID="navItemsDS" runat="server" XPath="/navigation/navItems/navItem[category='<%# XPath("category") %>']"  DataFile="~/App_Theme/project/productslist.xml"/> 

     <asp:Repeater ID="Repeater1" runat="server" DataSourceID="navItemsDS" >
         <HeaderTemplate> 
            <ul>
         </HeaderTemplate>
        <ItemTemplate>
            <li><a href="productdetail.html?page=products&amp;id=<%# XPath("prodctid") %>"><%# XPath("producttitle") %></a></li>
        </ItemTemplate>
        <FooterTemplate>
            </ul>
        </FooterTemplate>
     </asp:Repeater>

     ... etc

This does not work however.

How do I go about achieving this in .NET 2.0.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top