Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 960303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:09:44+00:00 2026-05-16T01:09:44+00:00

I am reading XML using xmlreader, and then binding the xml to a Repeater

  • 0

I am reading XML using xmlreader, and then binding the xml to a Repeater

Here’s the code behind:

            XmlReaderSettings settings = new XmlReaderSettings();
        settings.ProhibitDtd = false;

        XmlReader xmlData = XmlReader.Create(webClient.OpenRead(requestUrl), settings);

        try
        {
            xmlData.ReadToFollowing("SearchResults");
            Label1.Text = xmlData.GetAttribute("TotalCount");
            int numberResults = Convert.ToInt32(xmlData.GetAttribute("TotalCount"));
            if (numberResults > 0)
            {
                DataSet ds = new DataSet();
                ds.ReadXml(xmlData);
                Repeater1.DataSource = ds.Tables[1];
                Repeater1.DataBind();
            }
            else
            {
                Repeater1.DataSource = null;
                Repeater1.DataBind();
            }
        }

Here’s the repeater

        <asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate><b>Results</b><br /><br /></HeaderTemplate>
    <ItemTemplate>
   <a href="<%#DataBinder.Eval(Container.DataItem, "Url")%>">
    <%#DataBinder.Eval(Container.DataItem, "Title")%></a><br />
    </ItemTemplate>
    </asp:Repeater>

And the xml looks like:

  <SearchResults PageSize="1" PageIndex="0" TotalCount="155">
<SearchResult>
  <ContentId>2458</ContentId>
  <Title>Component description</Title>
  <Url>http://whatever/19/p/1537/2458.aspx</Url>
  <Date>2009-06-10T09:34:00+01:00</Date>
  <ContentType>forum</ContentType>
  <Tags>
    <Tag>Component</Tag>
  </Tags>
  <Users>
    <User>
      <Id>2533</Id>
      <DisplayName>Haubent</DisplayName>
      <Username>Haubent</Username>
    </User>
  </Users>
  <IndexedAt>2010-07-29T15:40:52.414+01:00</IndexedAt>
</SearchResult>

So far so good.

But – I want to be able to show the contents of the DisplayName node in my repeater item template.

I tried

<%#DataBinder.Eval(Container.DataItem, "DisplayName")%>

and

<%#DataBinder.Eval(Container.DataItem, "Users.User.DisplayName")%>

but I get an error:

System.Web.HttpException: DataBinding: ‘System.Data.DataRowView’ does not contain a property with the name ‘Users’.

How to get at the DisplayName?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:09:45+00:00Added an answer on May 16, 2026 at 1:09 am

    I think the best (and most natural) way to do this is by using Linq To XML.
    You can change your try block in this way:

    try
    {
        xmlData.ReadToFollowing("SearchResults");
        Label1.Text = xmlData.GetAttribute("TotalCount");
        int numberResults = Convert.ToInt32(xmlData.GetAttribute("TotalCount"));
        if (numberResults > 0)
        {
            XDocument xml = XDocument.Parse(xmlData.ReadOuterXml());
    
            Repeater1.DataSource = xml.Element("SearchResults").Elements("SearchResult");
            Repeater1.DataBind();
        }
        else
        {
            Repeater1.DataSource = null;
            Repeater1.DataBind();
        }
    }
    catch 
    {
        // do some catch
    }
    

    passing an XElement collection to de repeater. Then you can declare an OnRepeaterDataBound method similar to this:

    protected void Repeater1_OnItemDataBound(object sender, RepeaterItemEventArgs e) 
    {
        if ((e.Item.ItemType == ListItemType.Item) || ((e.Item.ItemType == ListItemType.AlternatingItem))) 
        {
            XElement User = ((XElement)e.Item.DataItem).Element("Users").Element("User");
    
            HyperLink hlUrl = ((HyperLink)e.Item.FindControl("hlUrl"));
    
            hlUrl.NavigateUrl = ((XElement)e.Item.DataItem).Element("Url").Value;
            hlUrl.Text = User.Element("DisplayName").Value;
        }
    }
    

    Having the repeater as:

    <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_OnItemDataBound">
        <HeaderTemplate>
            <b>Results</b><br />
            <br />
        </HeaderTemplate>
        <ItemTemplate>
            <asp:HyperLink ID="hlUrl" runat="server" />
        </ItemTemplate>
    </asp:Repeater>
    

    On the Repeater1_OnItemDataBound you will be able to parse your xml in the way you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading some XML with XmlReader using the following code: XmlReaderSettings settings = new
I am reading an xml file using javascript and then I need to submit
I am reading a xml file with: $reader = new XMLReader(); $reader->xml($myXml, NULL, LIBXML_NOWARNIG
I am reading an XML string with XDocument XmlReader reader = XmlReader.Create(new StringReader(xmltext)); reader.Read();
I am reading xml gps data using xmlreader.read(). I want to output all coordinate
I having XMl file I am Reading All the Xml using this code .
When reading a XML file with linq to XML using a XDocument and there
I'm reading an xml file using Jaxb, now the contents of the xml file
I'm reading some XML with PHP and currently using the DOMDocument class to do
I've seen a technique of reading and writing XML to disk using only C#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.