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

Accessing XML Nodes in RadGrid

1 Answer 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 08 Jan 2009, 12:52 AM
If I have a simple XML file, like this:

<top>
  <customer aaa="sss">
    <name>Cust1</name>
    <phone>123456789</phone>
    <size>Large</size>
  </customer>
  <customer aaa="sss">
    <name>Cust2</name>
    <phone>987654321</phone>
    <size>Small</size>
  </customer>
</top>

And a RadGrid control like this... 

<telerik:RadGrid ID="SearchResultsRadGrid" runat="server">

  <MasterTableView
    AutoGenerateColumns="true"
    CommandItemDisplay="Top" >
    <Columns>
    </Columns>
  </MasterTableView>  

</telerik:RadGrid>
  
  
And I bind the XML to the Grid control via an XMLDataSource with this following code:

xmlDataSource.DataFile = @"C:\Development\TestArea\SimpleXML.xml";
xmlDataSource.XPath = "top/customer";
      
SearchResultsRadGrid.DataSource = xmlDataSource;
SearchResultsRadGrid.DataBind();       

I would expect to see rows of name, phone, and size columns.

Instead I get this error: "Cannot find any bindable properties in an item from the datasource" 

Rows and columns appear if I put attributes on the <customer> node, but this is not want is needed.

What am I missing to get the grid to display the data under the <customer> node?

Thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Jan 2009, 11:46 AM
Hi Mark,

One suggestion is that to bind the RadGrid to XML file using Dataset. Please check the example below which I tried this, using Dataset.

CS:
DataSet ds = new DataSet();  
ds.ReadXml(Server.MapPath(@"~\Customer.xml"));  
RadGrid1.DataSource = ds;  
RadGrid1.DataBind(); 

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None">  
     <MasterTableView> 
           <Columns> 
                  <telerik:GridBoundColumn DataField="name" HeaderText="name" UniqueName="column">  
                  </telerik:GridBoundColumn> 
                  <telerik:GridBoundColumn DataField="phone" HeaderText="phone" UniqueName="column1">  
                  </telerik:GridBoundColumn> 
                  <telerik:GridBoundColumn DataField="size" HeaderText="size" UniqueName="column2">  
                  </telerik:GridBoundColumn> 
           </Columns> 
     </MasterTableView> 
</telerik:RadGrid> 

Thanks,
Princy.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or