Solved

Export GridView contents to XML file or other format

Posted on 2011-09-07
5
644 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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