We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


xmlNodelist with repeater in asp.net

Medium Priority
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>
Watch Question

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.
DBAduck - Ben MillerSQL Server Architect

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>



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 ??
SQL Server Architect
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.


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Forced accept.

EE Admin
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.