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

Getting xml from GridView datasource

3 Answers 138 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pramod Goutham
Top achievements
Rank 1
Pramod Goutham asked on 31 Oct 2008, 03:14 PM
Hi there,

I'm trying to generate xml from the datasource of rad gridview. Following is how I'm binding data to the grid:

radgvParticulars.MasterGridViewTemplate.DataSource = dsTODetails.Tables[1];

I'm wrote the following code to extract the xml from the datasource:

DataSet ds = (DataSet)radgvParticulars.DataSource;
string strXml = ds.GetXml();

This throws an InvalidCastException - "Unable to cast DataTable object to DataSet object". Then I tried the same by writing the below code:

DataTable dt = new DataTable();
dt = (DataTable)radgvParticulars.DataSource;
DataSet dsnew = new DataSet();
dsnew.Tables.Add(dt);
string strXml = dsnew.GetXml();

But this throws another exception: "DataTable already belongs to another DataSet".

I'm unable to proceed further. Pls help.

Regards,
Pramod Goutham.

3 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 04 Nov 2008, 08:46 AM
Hello Pramod Goutham,

We will be glad to reply to your inquiry. Before that, however, please address the questions in your "Customizing Link Manager and changing skin" ticket so that we can assist you.

 
Best wishes,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Pramod Goutham
Top achievements
Rank 1
answered on 05 Nov 2008, 10:26 AM
Hi,

I have already closed that support ticket, after sending a working model of the project with the issues I had and their screenshots, through my superior.

I hope my queries can be answered here onwards?
0
Accepted
Nick
Telerik team
answered on 05 Nov 2008, 07:18 PM
Hello Pramod Goutham,

We will address your question, however it will be best to give us the information we have requested, because it will help us answer your future questions better. Thank you for understanding.

The RadGridView is always two-way synchronized with its datasource. So you do not need to take your datasource from the grid when needed. You can just use the original object (DataSet in this case):

dsTODetails.GetXml(); 

Here is a sample:

DataSet set;  
          
private void Form1_Load(object sender, EventArgs e)  
{  
    set = new DataSet();  
    DataTable t = new DataTable("table1");  
    t.Columns.Add("Column 1");  
    t.Rows.Add("1");  
              
    set.Tables.Add(t);  
              
    this.radGridView1.DataSource = set;  
    this.radGridView1.MasterGridViewTemplate.DataMember = "table1";    
}  
 
private void radButton1_Click(object sender, EventArgs e)  
{  
    Console.WriteLine(set.GetXml());  



Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Pramod Goutham
Top achievements
Rank 1
Answers by
Nick
Telerik team
Pramod Goutham
Top achievements
Rank 1
Share this question
or