【问题标题】:XMLDataSource with filter binding to a DropDownList带有过滤器绑定到 DropDownList 的 XMLDataSource
【发布时间】:2011-12-06 12:51:55
【问题描述】:

我有一个 XML

<AddressTypes>
  <AddressType name="OFFICE" value="OFFICE" status="true"/>
  <AddressType name="HOME" value="HOME" status="true"/>
  <AddressType name="PRIVATE" value="PRIVATE" status="false"/>
</AddressTypes>

我将它绑定到 DropDownList 之类的

<asp:DropDownList ID="AddressTypesList" runat="server"
            AppendDataBoundItems="true"
            CssClass="selectbox" 
            DataSourceID="AddressesXMLSource"
            DataTextField="name"
            DataValueField="value">
    <asp:ListItem Text="ALL" Value=""></asp:ListItem>
</asp:DropDownList>
<asp:XmlDataSource ID="AddressesXMLSource" runat="server" 
        DataFile="~/App_Data/AdressTypes.xml" 
        XPath="/AddressTypes/AddressType">
</asp:XmlDataSource>

我在这里得到了所有三个字段。但我想过滤结果,以便我可以只填充 status="true" 的 AddressType。该怎么做?

【问题讨论】:

    标签: c# asp.net xmldatasource


    【解决方案1】:

    尝试修改 XmlDataSource 中的 XPath 以包含 [@status = 'true'] 以仅包含与“true”状态匹配的元素。

    您的新 xpath 字符串将如下所示:

    /AddressTypes/AddressType[ @status = 'true' ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多