I have an XML DataSource which feeds a repeater control. However, I’m having some issues getting the actual data to be shown.
The XML DataSource contains a list of Thicknesses of materials (taken from a larger XML file), along with price, size and dimension data:
<Thickness>
<Thick>
<Size label="Thickness: 12"><![CDATA[12]]></Size>
<Price>5778</Price>
<From>0</From>
<To>0</To>
</Thick>
<Thick>
<Size label="Thickness: 22"><![CDATA[22]]></Size>
<Price>5919</Price>
<From>0</From>
<To>0</To>
</Thick>
...
</Thickness>
I load the DataSource with the following code:
myThickness.XPath = "/Item[@label='" + tvwMaterials.SelectedNode.Text + "']/Thickness/*";
myThickness.DataBind();
(The other XPath stuff is just to get to the Thickness stuff). I then attempt to load it into the repeater (which is databound to the XML DataSource) and display it using the following code:
<ItemTemplate>
<table>
<tr>
<td><asp:Label ID="lblThickness" runat="server" Text="Thickness: " />
<asp:TextBox ID="txtThickness" runat="server" Text='<%# XPath("Thick/Size") %>' />
</tr><tr>
<td><asp:Label ID="Label2" runat="server" Text="From: " />
<asp:TextBox ID="TextBox1" runat="server" Text='<%# XPath("Thick/From") %>' />
/tr>
</table>
</ItemTemplate>
This correctly loads the number of controls, but the controls do not show any data. If I change the xPAth in the loading event to:
myThickness.XPath = "/Item[@label='" + tvwMaterials.SelectedNode.Text + "']/Thickness";
Then the controls do show data, but only for the very first record (12 and 0). I am not familiar enough with xPAth yet to figure out whteher the /* behind Thickness is needed or not, and if it is, how I then would copnstruct the xPAth in the repeater to read out the values. Anyone have any pointers, please?
Thanks in advance!
Load it like this:
Your datasource path must refer the repeating element in the xml document.