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

Populate Grid from xml

4 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
smith spd
Top achievements
Rank 1
smith spd asked on 07 Jun 2010, 08:51 PM
Hi,

I have been going through instances to populate the Grid from xml. But, my issue is I want to use the DOM model to populate the grid dynamically from Server side.
If I have a xml that looks something like this:
<Listing> 
  <Customer Name="Browning Bob" CustNumber="345" CustomerID="1" Address="123 Street1, 1 Coast, UK 89869" /> 
  <Customer Name="Williams" CustNumber="235" CustomerID="2" Address="123 Street2, Coast2, UK 89863" /> 
</Listing> 
I create an instance of xmldocument and try to load this xml into it but it says: data at root level is invalid.
Would be great if provided with sample code to use xpath + xmldom to populate the columns Name, CustNumber and Address dynamically from server side. Also, Please suggest, how to get paging controlled.

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 Jun 2010, 09:44 PM
Hello Smith,

You could use the XmlDataSource control for that purpose:
Population/data editing with XmlDataSource control

<asp:XmlDataSource ID="XmlDataSource1" runat="server"></asp:XmlDataSource>

protected void Page_Load(object sender, EventArgs e)
{
    ...
    string xmlData = "<Listing>" +
"<Customer Name=\"Browning Bob\" CustNumber=\"345\" CustomerID=\"1\" Address=\"123 Street1, 1 Coast, UK 89869\" /> " +
"<Customer Name=\"Williams\" CustNumber=\"235\" CustomerID=\"2\" Address=\"123 Street2, Coast2, UK 89863\" />" +
"</Listing>";
    XmlDataSource1.Data = xmlData;
    radGrid1.DataSourceID = XmlDataSource1.ID;
    ...
}


Best regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
smith spd
Top achievements
Rank 1
answered on 08 Jun 2010, 12:43 AM
Thanks for the response Daniel.

Why I maynot be able to use the Xmldocument instance and load the xml into it? Then, use this as xmldatasource.
In the sense, I donno what the xml looks like. This is just a structure of what I expect and I don't want to hard code it.

Please suggest some way so that I can be able to iterate through the xmlnodes from code behind to display the attribute value as column name and other nodes as data under each column using xpath and DOM model.

0
Daniel
Telerik team
answered on 11 Jun 2010, 02:23 PM
Hello Smith,

It is not possible to bind RadGrid to XmlDocument directly. The easiest approach could be to use the XmlDataSource as a mediator.

Please examine the attached demo.

Regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
smith spd
Top achievements
Rank 1
answered on 11 Jun 2010, 05:38 PM
Hello Daniel,

Thank you for the clarification.
Tags
Grid
Asked by
smith spd
Top achievements
Rank 1
Answers by
Daniel
Telerik team
smith spd
Top achievements
Rank 1
Share this question
or