我有一个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。如何做到这一点?
发布于 2011-12-06 21:28:20
尝试修改XmlDataSource中的状态,使其包含@status = 'true‘,以便只包含与"true“状态匹配的元素。
您的新xpath字符串将如下所示:
/AddressTypes/AddressType[ @status = 'true' ]https://stackoverflow.com/questions/8400177
复制相似问题