?
Solved

Export GridView contents to XML file or other format

Posted on 2011-09-07
5
Medium Priority
?
680 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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