Question

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?

Was it helpful?

Solution

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:

/AddressTypes/AddressType[ @status = 'true' ]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top