0

如果我有一个这样的 xml 文件:

 <?xml version="1.0" encoding="utf-8" ?> 
<Employees> 
   <Employee Department="Sales"> 
      <Name>David</Name> 
      <Salary>20000</Salary> 
   </Employee> 
   <Employee Department="Finance"> 
      <Name>Simon</Name> 
      <Salary>18000</Salary> 
   </Employee> 
   <Employee Department="Accounts"> 
      <Name>Peter</Name> 
      <Salary>22000</Salary> 
   </Employee> 
</Employees>

然后数据显示在转发器中,如下所示:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1">
   <ItemTemplate>
      <strong> 
     <%# XPath("@Department")%><br /> 
  </strong> 
  - Name: <%#XPath("Name")%><br /> 
  - Salary: <%#XPath("Salary")%><br />  
   </ItemTemplate>
</asp:Repeater>

我怎样才能只显示销售部门的员工?这是在一个 asp.net webapp 中。

4

2 回答 2

1

尝试在数据源上使用 XPath。

<asp:XmlDataSource DataFile="data.xml" runat="server" ID="XmlDataSource1" XPath="/Employees/Employee[@Department='Sales']" />

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1">
   <ItemTemplate>
    <strong>Department: <%# XPath("@Department")%><br /></strong> 
    - Name: <%#XPath("Name")%><br /> 
    - Salary: <%#XPath("Salary")%><br />  
   </ItemTemplate>
</asp:Repeater>

输出

Department: Sales
- Name: David
- Salary: 20000
于 2012-06-29T02:29:03.530 回答
0

数据在后台使用过滤器作为数据源Repeater,貌似不能

于 2012-06-29T02:12:18.823 回答