具有绑定到 DropDownList 的筛选器的 XMLDataSource
我有一个 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。怎么做呢?
I have an XML
<AddressTypes>
<AddressType name="OFFICE" value="OFFICE" status="true"/>
<AddressType name="HOME" value="HOME" status="true"/>
<AddressType name="PRIVATE" value="PRIVATE" status="false"/>
</AddressTypes>
I bind this to a DropDownList like
<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>
I get all the three fields here. But I would like to filter the result so that I may populate only AddressType where status="true". How to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试修改 XmlDataSource 中的 XPath 以包含 [ @status = 'true'] 以仅包含与“true”状态匹配的元素。
你的新 xpath 字符串将如下所示:
Try modifying your XPath in your XmlDataSource to include [ @status = 'true'] to only include the elements that match the "true" status.
Your new xpath string would look like this then: