?
Solved

Export DataGrid to XML

Posted on 2006-11-29
12
Medium Priority
?
674 Views
Last Modified: 2008-02-01
I am looking for a way to export a datagrid to xml regardless of its source type.  I have several datagrids where their source types are of type DataTable and ArrayList.  I was attempting to write a class where the datagrid would be passed and the class would handle the export.  Any suggestions?
0
Comment
Question by:Cwinde01
[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
  • 6
  • 5
12 Comments
 
LVL 7

Expert Comment

by:Dimandja
ID: 18040150
Try http://tinyurl.com/ufc87

In VB.NET, the code would be:

         Dim sw as new StringWriter()
         Dim hw as new  HtmlTextWriter(sw)
         DataGrid1.RenderControl(hw)

         With hw
            .Indentation = 4
            .WriteEndDocumnet()
         End with

         hw.Close()
         MsgBox(sw.ToString())


 
0
 

Author Comment

by:Cwinde01
ID: 18040211
I am using Vb.Net 2003.  I don't think RenderControl is a member of the datagrid in 2003.  Any other suggestions?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18044841
There was an assumption made--that you were using the DataGrid web control with an ASP.NET application.  If you are using the WinForms DataGrid, then how are you binding the DataGrid?  DataTable?  DataSet?

Bob
0
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.

 

Author Comment

by:Cwinde01
ID: 18045569
There are several grids that are loaded.  Most of the time we will set datagrid.datasource = dataset.tables("TableName") and other times we will set datagrid.datasource = ArrayList.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18045598
Saving a DataSet to XML can be as easy as using DataSet.WriteXml, but the ArrayList is a different story all together.

Bob
0
 

Author Comment

by:Cwinde01
ID: 18045712
That is what I was afraid of.  I have used the DataSet.WriteXml before but I was trying to find a way to extract the data from the datagrid.datasource.  Maybe another solution might be to set the datagrid.datasource to a dataset somehow.  But I have not been able to do that either.  I tried CType(Me.DataGrid.DataSource, DataTable), but when the arraylist is the datasource CType is unable to convert it into a DataTable.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18046788
I need to find out the reason for mixing DataSet/DataTable and ArrayList as a binding source.

Bob
0
 

Author Comment

by:Cwinde01
ID: 18047183
Sorry for the confusion.  I have an application that has several datagrids.  

* Some of the datagrids are loaded using a DataSet.  

* Then there are other datagrids that are loaded using a dataview because I need to filter the dataset based on the selection made from another datagrid.  

* Then I have one instance where I have a datagrid that has two different datasources.  I query the first datasource and load the results into a arraylist then I query the second source and load the results in the same arraylist.  Then assign the arraylist to the datagrid.datasource so that it appears as one source.  I realize now that the data should have been loaded manualy using a datatable.  I was hoping that I would not have to rewrite the piece that loads the arraylist.

I have one scenario where I want to show all the different grids on one xml page and show a summary for each grid.  I would have a style sheet to handle the summary but  I need to get the different grids into the same doc.

Hope that helps.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18047758
Hmmm, maybe you could something like this:

  Dim dv1 As New DataView(ds.Tables("Table1"))
  Dim dv2 As New DataView(ds.Tables("Table2"))

  dv1.RowFilter = "filter goes here"
  dv2.RowFilter = "filter goes here"

  Me.DataGrid1.DataSource = dv1
  Me.DataGrid2.DataSource = dv2

Then, you could create an XML file from the DataView.  You would only need to create one method to create the file.

Bob
0
 

Author Comment

by:Cwinde01
ID: 18047865
It appears that I will need to convert everthing to a dataview or a datatable, is that correct?

I guess there is no way to extrapolate the datagrid.datasource to some other type of datasource? (arraylist, datatable, dataview)
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 18047955
1) You don't need an ArrayList

2) The DataView constructor takes a DataTable as an argument

3) With the DataView you can apply different filters for each separate instance

4) If you bind all DataGrid controls to a DataView, then you can retrieve the DataSource this way:

  Dim dv As DataView = CType(CType(source, DataGrid).Datasource, DataView)

Bob
0
 

Author Comment

by:Cwinde01
ID: 18047975
It looks like that should work.

Thank you for your help and explanations.  Your patience has been greatly appreciated.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 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