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

Populating radgrid from XML data

3 Answers 215 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mesha
Top achievements
Rank 1
mesha asked on 22 Oct 2008, 03:16 PM
Hi,

I would like to display the data in radgrid which will pick the xml data.

Following is my query:

I have a data in XML string in my code in the following format

<Customers>
<CustomerID>1</CustomerID>
<CustomerName>xxx</CustomerName>
<CustomerID>2</CustomerID>
<CustomerName>yyy</CustomerName>

</Customers>

I would like to display the above data in radgrid like following

CustomerID            CustomerName
1                              xxx
2                              yyy

I don't have the data in physical XML file and all the above data will in XML string.

I had a chance to look at the demo examples, unfortunately i could not find the solution.

Kindly help me...

If possible please post a sample code.

Thanks,
Shashi

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 Oct 2008, 03:58 PM
Hello Mesha,

Please examine the example below. It illustrates a possible approach.

xml string
<Customers> 
  <Customer ID="1" Name="xxx" /> 
  <Customer ID="2" Name="yyy" /> 
</Customers> 

code:
StringReader streamreader = new StringReader(xmlstring); 
XmlTextReader xmlreader = new XmlTextReader(streamreader ); 
DataSet dataset = new DataSet(); 
dataset .ReadXml(xmlreader); 
RadGrid1.DataSource = dataset ; 

I hope this helps.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
oguzhan
Top achievements
Rank 1
answered on 21 Jul 2010, 03:14 PM
Hi,
When i add this code to load event it is working but when i add the button click event it is not working.
thanks
0
Daniel
Telerik team
answered on 27 Jul 2010, 09:33 AM
Hello Oguzhan,

You have to rebind RadGrid as demonstrated below:
protected void Button1_Click(object sender, EventArgs e)
{
    string xmlstring = "<Customers><Customer ID=\"1\" Name=\"xxx\" /><Customer ID=\"2\" Name=\"yyy\" /></Customers>";
    System.IO.StringReader streamreader = new System.IO.StringReader(xmlstring);
    System.Xml.XmlTextReader xmlreader = new System.Xml.XmlTextReader(streamreader);
    System.Data.DataSet dataset = new System.Data.DataSet();
    dataset.ReadXml(xmlreader);
    RadGrid1.DataSource = dataset;
    RadGrid1.Rebind();
}

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
Tags
Grid
Asked by
mesha
Top achievements
Rank 1
Answers by
Daniel
Telerik team
oguzhan
Top achievements
Rank 1
Share this question
or