xmlNodelist with repeater in

Posted on 2007-07-19
Last Modified: 2013-11-18
I have a an XML string called xmlList =

I would like to bind it to a asp:repeater control and access these elements.

I use this psudo code:

xmlDoc xmlDocument()

XmlNodeList dataSourceNodeList = xmlDoc.SelectNodes("DataList/DataItem");

rpListItems.DataSource = dataSourceNodeList

What syntax do I use to display particular items in each node - like so?:

<asp:Repeater id="rpListItems" runat="server">
<td><%# ((XmlNode)Container.DataItem).(DataItem/name) %></td>
<td><%# ((XmlNode)Container.DataItem).(DataItem/email) %></td>
Question by:simshp
    LVL 12

    Expert Comment

    try this...

    <asp:Label Id="lblName" runat="server" Text='<%# Bind("name") %>'></asp:Label>
    <asp:Label Id="lblEmail" runat="server" Text='<%# Bind("email") %>'></asp:Label>

    If you want more of a table look you should think about using a gridview instead.
    LVL 24

    Expert Comment

    by:DBAduck - Ben Miller
    You should be able to do something like this:

    A little variation of above.

    <asp:Label Id="lblName" runat="server" Text='<%# Eval("name") %>'></asp:Label>
    <asp:Label Id="lblEmail" runat="server" Text='<%# Eval("email") %>'></asp:Label>


    Author Comment

    Tried both methods to no avail. Solved the problem using a dataset:

                Dim ds As DataSet = New DataSet
                ds.ReadXml(New StringReader(xmlList))

                rpDirectoryItems.DataSource = ds

    and the following to bind in the repeater :

    '<%# DataBinder.Eval(Container, "DataItem.Name") %>'
    '<%# DataBinder.Eval(Container, "DataItem.Email") %>'

    Would be nice to know how to bind using only xml and xpaths :

                'xmlDoc = New XmlDocument

    Dim xmlDirSummaryList As XmlNodeList = xmlDoc.SelectNodes("/DirSummaryList/DirSummaryItem")
              rpDirectoryItems.DataSource = xmlDirSummaryList

    How to bind in the aspx file ??
    LVL 24

    Accepted Solution

    That would work, but you could also look at the XmlDataSource as well.

    That is if the data is in a file, which it apparently is not according to your code above.  So if you saved it in a file, then you could, but otherwise, I do not believe that you can DataBind XML directly according to the documentation.  Next time I will test the code before suggesting :-).

    The DataSet way is the most common way to get this done.

    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Expert Comment

    Having this XML:

    <book id="1" name="Ivan"/>
    <book id="1" name="Pedro"/>

    You can bind an XmlNodeList (the name attribute in this example) in an asp:Repeater element using the following expression:
    <%# DataBinder.Eval(((System.Xml.XmlNode)(Container.DataItem)).Attributes["name"], "Value") %>

    Regards ;),
    Iván Sainz

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now