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

Bit of help with binding grid to XML

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael Dunbar
Top achievements
Rank 2
Michael Dunbar asked on 21 Oct 2009, 08:45 AM
Hello,

I followed the online documentation and have almost got the grid populating from an XML file. The problem is although the grid is finding the nodes via the DataKeyName I have set, it is not reading the child nodes of that node it has found. So I am getting 10 empty rows, which is currently the right number of Topics/XML nodes. Here is my code to try to explain further:

XML
<Topics> 
  <Topic TopicId="1"
    <TopicName>Test</TopicName> 
    <Categories> 
      <Category>Category 1</Category> 
      <Category>Category 2</Category> 
    </Categories> 
    <FileName>Test.html</FileName> 
  </Topic> 
</Topics> 

HTML
<telerik:RadGrid ID="gridLearningList" runat="server"
                    <MasterTableView AutoGenerateColumns="false" DataKeyNames="TopicId"
                   <Columns> 
                     <telerik:GridBoundColumn 
                        DataField="TopicName" 
                        HeaderText="Learning topic"
                     </telerik:GridBoundColumn> 
                     <telerik:GridBoundColumn 
                        DataField="Categories" 
                        HeaderText="Category"
                     </telerik:GridBoundColumn> 
                     <telerik:GridBoundColumn 
                        DataField="FileName" 
                        HeaderText="File name"
                     </telerik:GridBoundColumn> 
                   </Columns> 
                 </MasterTableView> 
                    </telerik:RadGrid> 
                    <asp:XmlDataSource ID="dsLearningList" runat="server" /> 

C#
private void PopulateLearningList() 
    { 
        dsLearningList.DataFile = "~/App_Data/OnlineLearningTopics.xml"
        gridLearningList.DataSourceID = "dsLearningList"
        gridLearningList.DataBind(); 
    } 

How do I bind each column to the child node (i.e. TopicName) of the node it has found (i.e. Topic). Surely it is just a case of mapping it correctly somehow?

Thanks,

Michael

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Oct 2009, 11:00 AM
Hello Michael,

Your XML data needs to be transformed using XSLT before your grid can read the data. Here's a link which explains on how to use XmlDataSource with a GridView after transforming the xml file:
How to use an XMLDataSource with a GridView

Hope this helps..
Princy.


Tags
Grid
Asked by
Michael Dunbar
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or