Hi all,
I am stuck on a problem. I think I am probably close to the solution but can not seem to get there. I have an XMLDoc that is loaded from a stored Proc, into a dataset and the xml is pulled from it, (don't think I can change any of this part). The XML looks like this:
<data>
<datanode>
<name>11</name>
<group>G1</group>
<value>val1</value>
</datanode>
<datanode>
<name>12</name>
<group>G1</group>
<value>val2</value>
</datanode>
<datanode>
<name>21</name>
<group>G2</group>
<value>val1</value>
</datanode>
<datanode>
<name>22</name>
<group>G2</group>
<value>val2</value>
</datanode>
<datanode>
<name>23</name>
<group>G2</group>
<value>val3</value>
</datanode>
<datanode>
<name>31</name>
<group>G3</group>
<value>val1</value>
</datanode>
<datanode>
<name>32</name>
<group>G3</group>
<value>val2</value>
</datanode>
<datanode>
<name>33</name>
<group>G3</group>
<value>val3</value>
</datanode>
<datanode>
<name>34</name>
<group>G3</group>
<value>val4</value>
</datanode>
</data>
I need to use nested repeaters to display this information. What I want is to group it by the "group" node then show each of the "datanodes" that belong to that "group" node. So it would look something like this on the page:
G1 - has 2 nodes
11 - Val1
12 - Val2
G2 - has 3 nodes
21 - Val1
22 - Val2
23 - Val3
etc
What I have so far: Default.aspx:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<p>
COUNT: <asp:Literal runat="server" ID="Literal3" Text='<%# XPath("count(group)") %>' />
<br />Text: <asp:Literal runat="server" ID="Literal4" Text='<%# XPath("text()") %>' />
<br />Group: <asp:Literal runat="server" ID="Literal2" Text='<%# XPath("group") %>' />
<br />ID: <asp:Literal runat="server" ID="displayname" Text='<%# XPath("name") %>' />
<br />VAL: <asp:Literal runat="server" ID="Literal1" Text='<%# XPath("value") %>' />
</p>
</ItemTemplate>
</asp:Repeater>
Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
private XmlNodeList nodelist;
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"C:\development\testforWork\WebApplication1\WebApplication1\data.xml");
nodelist = doc.SelectNodes("//datanode[not(group=preceding-sibling::datanode/group)]/group");
//nodelist = doc.SelectNodes("//datanode[group='G2']");
Repeater1.DataSource = nodelist;
Repeater1.DataBind();
}
}
I can get them to just display each datanode one after the other, but I can not figure out how to nest the repeaters and do the grouping. I am newish to XPath and repeaters and think I must have some gap in my knowledge and just can't connect the dots, (unless I am running down the wrong road entirely).
Thanks