Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Export GridView contents to XML file or other format

Posted on 2011-09-07
5
Medium Priority
?
696 Views
Last Modified: 2012-08-13
Hi,

I am using a component one as.net gridview. This will be used to display data from a variety of sources. I would like to be able to use the component one ReportViewer control to allow the user to view, print and export the contents of the GridView. This is so they can use the in-built features of the GridView control to filter, group, etc.

My thinking at the moment is I will need to somehow create an XML file based upon the format and data of the GridView and then use this XML as the source for the ReportViewer.

Does anyone have any suggestions on the best way to approach this or is my thinking the best way? Any suggestions appreciated.
0
Comment
Question by:MooksUK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:MooksUK
ID: 36497280
In addition to the above. I believe I will have to create an RDL file which will be used to format the report and then save the data in an XML file. These can then be used by the ReportViewer. This seems a lengthy approach and would be very interested in any quicker way of achieving the same.
0
 
LVL 12

Expert Comment

by:starlite551
ID: 36505974
Try this code :
public static string GetXMLGridView(GridView gridview)
{
      DataTable dt = gridview.DataSource as DataTable;
      DataSet ds = new DataSet();
      ds.Tables.Add(dt);      
      string xmlContent = ds.GetXml();      
      return xmlContent;
}

Open in new window

0
 
LVL 12

Expert Comment

by:starlite551
ID: 36505997
The above Method returns the content of a GridView in XML format string. Without starting tags which specify the version of Xml used.
0
 
LVL 12

Accepted Solution

by:
starlite551 earned 2000 total points
ID: 36506112
You can create a physical XML File using this code :
ds.WriteXml(@"C:\MyXMLFile.xml");

Open in new window

public static void GetXMLGridView(GridView gridview,string filePath)
{
      DataTable dt = gridview.DataSource as DataTable;
      DataSet ds = new DataSet();
      ds.Tables.Add(dt);      
      ds.WriteXml(filePath);            
}

Open in new window


Method Usage :
 
GetXMLGridView(gridview,@"C:\MyXML.xml");

Open in new window

0
 

Author Closing Comment

by:MooksUK
ID: 36530523
Thanks, this answered part of the problem. I will look to produce the XSD file from it as well so that this can be used by the report viewer component.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Screencast - Getting to Know the Pipeline

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question