我正在尝试构建产品详细信息页面菜单导航,并且只想显示同一类别中产品的导航项。
数据保存在两个不同的 XML 文件中。一个包含当前产品数据,一个包含导航信息。两者都包含“类别”作为元素。
我想使用另一个 XmlDataSource,然后将当前产品类别从父容器(可使用 XPath("category") 访问)传递到 XPath 属性以过滤值。
然后我会将这个过滤后的数据源传递给转发器进行渲染。
<%-- 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&id=<%# XPath("prodctid") %>"><%# XPath("producttitle") %></a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
... etc
但是,这不起作用。
我如何在 .NET 2.0 中实现这一点。