EDN Admin
Well-known member
Hey all, Im trying to nest DataLists in an ASP.NET page and display data from a single XML file. A sample of my XML file is as follows:<br/>
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; Students<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Student <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; " <span style="color:Red; birthday<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 04/20/1976<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Jack<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Dog<span style="color:Black; "<span style="color:Blue; >Missy<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Dog<span style="color:Black; "<span style="color:Blue; >Monty<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Cat<span style="color:Black; "<span style="color:Blue; >Felix<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Student<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Student <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 2<span style="color:Black; " <span style="color:Red; birthday<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 12/04/1995<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Jill<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Snake<span style="color:Black; "<span style="color:Blue; >Fido<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Student<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Student <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3<span style="color:Black; " <span style="color:Red; birthday<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 05/04/1986<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Jane<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Cat<span style="color:Black; "<span style="color:Blue; >Fluffy<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Cat<span style="color:Black; "<span style="color:Blue; >Sir. Winston of Canterbury, the Third<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Cat<span style="color:Black; "<span style="color:Blue; >Envy<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Rabbit<span style="color:Black; "<span style="color:Blue; >Snuggles<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Student<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Student <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 4<span style="color:Black; " <span style="color:Red; birthday<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 03/12/1985<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >John<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Dog<span style="color:Black; "<span style="color:Blue; >Daisy<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Dog<span style="color:Black; "<span style="color:Blue; >Duke<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Student<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Students<span style="color:Blue; >
[/code]
In my XML Data Source, I call the single XML file without specifying an .XSL or XPath Expression. Then, in my DataList (which references the XMLDataSource), I have the following markup:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; XmlDataSource <span style="color:Red; ID<span style="color:Blue; =<span style="color:Blue; "XmlDataSource1" <span style="color:Red; runat<span style="color:Blue; =<span style="color:Blue; "server" <span style="color:Red; DataFile<span style="color:Blue; =<span style="color:Blue; "~/App_Data/Students.xml"<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; XmlDataSource<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; DataList <span style="color:Red; ID<span style="color:Blue; =<span style="color:Blue; "students" <span style="color:Red; runat<span style="color:Blue; =<span style="color:Blue; "server" <span style="color:Red; DataSourceID<span style="color:Blue; =<span style="color:Blue; "XmlDataSource1"<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ItemTemplate<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h4<span style="color:Blue; >
<span style="background-color:Yellow; <%# XPath("Name") <span style="background-color:Yellow; %>
(<span style="background-color:Yellow; <%# XPath("Name/../@id") <span style="background-color:Yellow; %>)<span style="color:Blue; </<span style="color:#A31515; h4<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; DataList <span style="color:Red; ID<span style="color:Blue; =<span style="color:Blue; "pets" <span style="color:Red; runat<span style="color:Blue; =<span style="color:Blue; "server" <span style="color:Red; DataSourceID<span style="color:Blue; =<span style="color:Blue; "XmlDataSource1"<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ItemTemplate<span style="color:Blue; >
<span style="background-color:Yellow; <%# XPath("Student[Name/../@id]/Pets/Pet") <span style="background-color:Yellow; %> (<span style="background-color:Yellow; <%# XPath("Student[Name/../@id]/Pets/Pet/@type")<span style="background-color:Yellow; %>)<span style="color:Blue; </<span style="color:#A31515; ItemTemplate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; DataList<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; ItemTemplate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; DataList<span style="color:Blue; >
[/code]
<br/>
The first part of my page displays correctly (where each students name prints, along with the ID), but the nested DataList isnt populating with anything. Does anyone have a suggestion on how I can get each pet to list beneath their respective student?
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; Students<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Student <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; " <span style="color:Red; birthday<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 04/20/1976<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Jack<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Dog<span style="color:Black; "<span style="color:Blue; >Missy<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Dog<span style="color:Black; "<span style="color:Blue; >Monty<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Cat<span style="color:Black; "<span style="color:Blue; >Felix<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Student<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Student <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 2<span style="color:Black; " <span style="color:Red; birthday<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 12/04/1995<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Jill<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Snake<span style="color:Black; "<span style="color:Blue; >Fido<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Student<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Student <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3<span style="color:Black; " <span style="color:Red; birthday<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 05/04/1986<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >Jane<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Cat<span style="color:Black; "<span style="color:Blue; >Fluffy<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Cat<span style="color:Black; "<span style="color:Blue; >Sir. Winston of Canterbury, the Third<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Cat<span style="color:Black; "<span style="color:Blue; >Envy<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Rabbit<span style="color:Black; "<span style="color:Blue; >Snuggles<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Student<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Student <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 4<span style="color:Black; " <span style="color:Red; birthday<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 03/12/1985<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Name<span style="color:Blue; >John<span style="color:Blue; </<span style="color:#A31515; Name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Dog<span style="color:Black; "<span style="color:Blue; >Daisy<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pet <span style="color:Red; type<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Dog<span style="color:Black; "<span style="color:Blue; >Duke<span style="color:Blue; </<span style="color:#A31515; Pet<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Pets<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Student<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Students<span style="color:Blue; >
[/code]
In my XML Data Source, I call the single XML file without specifying an .XSL or XPath Expression. Then, in my DataList (which references the XMLDataSource), I have the following markup:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; XmlDataSource <span style="color:Red; ID<span style="color:Blue; =<span style="color:Blue; "XmlDataSource1" <span style="color:Red; runat<span style="color:Blue; =<span style="color:Blue; "server" <span style="color:Red; DataFile<span style="color:Blue; =<span style="color:Blue; "~/App_Data/Students.xml"<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; XmlDataSource<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; DataList <span style="color:Red; ID<span style="color:Blue; =<span style="color:Blue; "students" <span style="color:Red; runat<span style="color:Blue; =<span style="color:Blue; "server" <span style="color:Red; DataSourceID<span style="color:Blue; =<span style="color:Blue; "XmlDataSource1"<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ItemTemplate<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h4<span style="color:Blue; >
<span style="background-color:Yellow; <%# XPath("Name") <span style="background-color:Yellow; %>
(<span style="background-color:Yellow; <%# XPath("Name/../@id") <span style="background-color:Yellow; %>)<span style="color:Blue; </<span style="color:#A31515; h4<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; DataList <span style="color:Red; ID<span style="color:Blue; =<span style="color:Blue; "pets" <span style="color:Red; runat<span style="color:Blue; =<span style="color:Blue; "server" <span style="color:Red; DataSourceID<span style="color:Blue; =<span style="color:Blue; "XmlDataSource1"<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ItemTemplate<span style="color:Blue; >
<span style="background-color:Yellow; <%# XPath("Student[Name/../@id]/Pets/Pet") <span style="background-color:Yellow; %> (<span style="background-color:Yellow; <%# XPath("Student[Name/../@id]/Pets/Pet/@type")<span style="background-color:Yellow; %>)<span style="color:Blue; </<span style="color:#A31515; ItemTemplate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; DataList<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; ItemTemplate<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; asp<span style="color:Blue; :<span style="color:#A31515; DataList<span style="color:Blue; >
[/code]
<br/>
The first part of my page displays correctly (where each students name prints, along with the ID), but the nested DataList isnt populating with anything. Does anyone have a suggestion on how I can get each pet to list beneath their respective student?
View the full article