This is a migrated thread and some comments may be shown as answers.

Hierarchical XML Data into a radGrid?

1 Answer 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 31 Aug 2012, 05:50 AM
Hi,

I have the following XML:

<foo>
  <bar>
    <abc label="bar: 1"><![CDATA[Guiness]]></abc>
    <def>1234</def>
  </bar>
  <bar>
    <abc label="bar: 2"><![CDATA[Heineken]]></bar>
    <def>4567</def>
  </bar>
  ...
</foo>


This XML is loaded into a datasource using an XPath expression:

myXML.XPath = "/foo";

I now would like to use a radGrid to store all the info of the child-nodes of bar. In the example XML above, this would be the abc and def nodes, though the actual amount of them might differ. I'd like to have the individual child nodes of the bars displayed as columns.

So the desired outcome would be a grid displaying:

bar..........abc..........def
1............Guiness...1234
2............Heineken..4567

I tried directly binding to the XML, and played around with different XPAth statements trying to get things to work, but ended up with an error: Cannot find any bindable properties

Any ideas?

Thanks in advance!

Peter

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 05 Sep 2012, 06:59 AM
Hi Peter,

I have assembled a sample project demonstrating the desired functionality implemented. Note that in order to bind the RadGrid each column representation is an attribute not an individual element as it is shown below. 
<?xml version="1.0" encoding="utf-8" ?>
  
<foo>
  <bar abcLabel="bar: 1" def="1234">
  </bar>
  <bar abcLabel="bar: 2" def="2345">
  </bar>
</foo>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Data.xml"
    XPath="foo/bar"></asp:XmlDataSource>

Additionally, you could go through the code library below describing how you could implement your scenario using different approach.

Regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or