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?