xml xpath list in listview only showing 1st Node

Last post 07-02-2008 4:36 AM by Samu Zhang - MSFT. 1 replies.

Sort Posts:

  • xml xpath list in listview only showing 1st Node

    06-28-2008, 4:19 AM

    Hi, I am just wondering what i am doing wrong. When I use the listview like this:

     

            <asp:XmlDataSource
            id="XmlSourceT2"
            DataFile="/App_Data/cl.xml"
             XPath="courseList/category_background/security/tg1"
            runat="server" />

     <asp:ListView ID="ListView_tg" runat="server" DataSourceID="XmlSourceT2">
              <LayoutTemplate>            <ul>              <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />            </ul >          </LayoutTemplate>
              <EmptyDataTemplate>            <li>Error!</li>          </EmptyDataTemplate>
              <ItemTemplate>
          <li><%# Eval("@desc") %> </li> 
              </ItemTemplate>
            </asp:ListView>

    xml file:

       <security>

      <tg desc="some stuff #1." />
            <tg desc="some stuff #2." />
            <tg desc="some stuff #3." />

    ........

    </security>

    All three items will show.  But if i chose to use the XPATH as follows:

            <asp:XmlDataSource
            id="XmlSourceT2"
            DataFile="/App_Data/cl.xml"
             XPath="courseList/category_background/security"
            runat="server" />

        <li><%# XPath("tg1/@desc") %> </li> 

    Only the top list item shows - the other 2 are not listed.

     Cheers

    Tania

  • Re: xml xpath list in listview only showing 1st Node

    07-02-2008, 4:36 AM
    Answer

    Hi taniafarmer ,

    Yes , it will not show all the records. If you specify xpath to "courseList/category_background/security/tg" , this will generate one xmlNodelist like this : XmlNodeList lst = doc.SelectNodes("courseList/category_background/security/tg") , the length of lst is greater than one , so the ListView control will iterate each XmlNode in the lst and show each desc attribute in ItemTemplate . But if you use xpath "courseList/category_background/security" , the length of lst will be one , then ListView will only generate one item. So you must "tell" ListView control how much items it should render.

     

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter