473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Bind Datagrid to an xml string (not file)

Can I bind datagrid to an xml string (not to file)? For example, the result of transformation?
Nov 18 '05 #1
5 1623
Hi Mark,

No problem doing what you want to do. Here's one way, there are probably
many others.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' Ken Cox - Microsoft MVP [ASP.NET] Feb 13/04
' Create a stringbuilder to hold the XML
Dim sb As New System.Text.StringBuilder
' Create a dataset to hold the data
Dim ds As New DataSet
' create a TextReader to get the XML
Dim xmlrder As System.Xml.XmlTextReader
' Build some sample XML data (must be well-formed)
sb.Append("<?xml version=""1.0"" standalone=""yes""?>")
sb.Append("<CanadaPostalCodes>")
sb.Append("<Postal_Code>")
sb.Append("<FSA>A0A</FSA>")
sb.Append("<LDA>1A0</LDA>")
sb.Append("<Province>NEWFOUNDLAND AND LABRADOR</Province>")
sb.Append("<Type>Rural</Type>")
sb.Append("<DeliveryInstallation>AQUAFORTE
PO</DeliveryInstallation>")
sb.Append("<Key>1</Key>")
sb.Append("</Postal_Code>")
sb.Append("<Postal_Code>")
sb.Append("<FSA>A0A</FSA>")
sb.Append("<LDA>1B0</LDA>")
sb.Append("<Province>NEWFOUNDLAND AND LABRADOR</Province>")
sb.Append("<Type>Rural</Type>")
sb.Append("<DeliveryInstallation>AVONDALE
PO</DeliveryInstallation>")
sb.Append("<Key>2</Key>")
sb.Append("</Postal_Code>")
sb.Append("</CanadaPostalCodes>")
' Point the xmltextreader to the string full of xml and
' tell it to expect an XML document
xmlrder = New System.Xml.XmlTextReader _
(sb.ToString, System.Xml.XmlNodeType.Document, Nothing)
' Read all of the XML as one chunk
xmlrder.ReadOuterXml()
' Read the outer XML into the Dataset
ds.ReadXml(xmlrder)
' Tell the datagrid to use this dataset
DataGrid1.DataSource = ds
' Bind the data
DataGrid1.DataBind()
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

"Mark" <an*******@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
Can I bind datagrid to an xml string (not to file)? For example, the
result of transformation?


Nov 18 '05 #2
But how about to bind to a complete xml string (just like you would do with
the file) but without converting the string into a file first.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:O#**************@TK2MSFTNGP10.phx.gbl...
Hi Mark,

No problem doing what you want to do. Here's one way, there are probably
many others.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' Ken Cox - Microsoft MVP [ASP.NET] Feb 13/04
' Create a stringbuilder to hold the XML
Dim sb As New System.Text.StringBuilder
' Create a dataset to hold the data
Dim ds As New DataSet
' create a TextReader to get the XML
Dim xmlrder As System.Xml.XmlTextReader
' Build some sample XML data (must be well-formed)
sb.Append("<?xml version=""1.0"" standalone=""yes""?>")
sb.Append("<CanadaPostalCodes>")
sb.Append("<Postal_Code>")
sb.Append("<FSA>A0A</FSA>")
sb.Append("<LDA>1A0</LDA>")
sb.Append("<Province>NEWFOUNDLAND AND LABRADOR</Province>")
sb.Append("<Type>Rural</Type>")
sb.Append("<DeliveryInstallation>AQUAFORTE
PO</DeliveryInstallation>")
sb.Append("<Key>1</Key>")
sb.Append("</Postal_Code>")
sb.Append("<Postal_Code>")
sb.Append("<FSA>A0A</FSA>")
sb.Append("<LDA>1B0</LDA>")
sb.Append("<Province>NEWFOUNDLAND AND LABRADOR</Province>")
sb.Append("<Type>Rural</Type>")
sb.Append("<DeliveryInstallation>AVONDALE
PO</DeliveryInstallation>")
sb.Append("<Key>2</Key>")
sb.Append("</Postal_Code>")
sb.Append("</CanadaPostalCodes>")
' Point the xmltextreader to the string full of xml and
' tell it to expect an XML document
xmlrder = New System.Xml.XmlTextReader _
(sb.ToString, System.Xml.XmlNodeType.Document, Nothing)
' Read all of the XML as one chunk
xmlrder.ReadOuterXml()
' Read the outer XML into the Dataset
ds.ReadXml(xmlrder)
' Tell the datagrid to use this dataset
DataGrid1.DataSource = ds
' Bind the data
DataGrid1.DataBind()
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

"Mark" <an*******@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
Can I bind datagrid to an xml string (not to file)? For example, the
result of transformation?

Nov 18 '05 #3
Mark,
Ken's example is not converting xml to file in the example he provided.
Please look at the code again.
Hope this helps.
Marshal Antony
..NET Developer
http://www.dotnetmarshal.com

"Mark Goldin" <ma********@comcast.net> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
But how about to bind to a complete xml string (just like you would do with the file) but without converting the string into a file first.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:O#**************@TK2MSFTNGP10.phx.gbl...
Hi Mark,

No problem doing what you want to do. Here's one way, there are probably
many others.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' Ken Cox - Microsoft MVP [ASP.NET] Feb 13/04
' Create a stringbuilder to hold the XML
Dim sb As New System.Text.StringBuilder
' Create a dataset to hold the data
Dim ds As New DataSet
' create a TextReader to get the XML
Dim xmlrder As System.Xml.XmlTextReader
' Build some sample XML data (must be well-formed)
sb.Append("<?xml version=""1.0"" standalone=""yes""?>")
sb.Append("<CanadaPostalCodes>")
sb.Append("<Postal_Code>")
sb.Append("<FSA>A0A</FSA>")
sb.Append("<LDA>1A0</LDA>")
sb.Append("<Province>NEWFOUNDLAND AND LABRADOR</Province>")
sb.Append("<Type>Rural</Type>")
sb.Append("<DeliveryInstallation>AQUAFORTE
PO</DeliveryInstallation>")
sb.Append("<Key>1</Key>")
sb.Append("</Postal_Code>")
sb.Append("<Postal_Code>")
sb.Append("<FSA>A0A</FSA>")
sb.Append("<LDA>1B0</LDA>")
sb.Append("<Province>NEWFOUNDLAND AND LABRADOR</Province>")
sb.Append("<Type>Rural</Type>")
sb.Append("<DeliveryInstallation>AVONDALE
PO</DeliveryInstallation>")
sb.Append("<Key>2</Key>")
sb.Append("</Postal_Code>")
sb.Append("</CanadaPostalCodes>")
' Point the xmltextreader to the string full of xml and
' tell it to expect an XML document
xmlrder = New System.Xml.XmlTextReader _
(sb.ToString, System.Xml.XmlNodeType.Document, Nothing)
' Read all of the XML as one chunk
xmlrder.ReadOuterXml()
' Read the outer XML into the Dataset
ds.ReadXml(xmlrder)
' Tell the datagrid to use this dataset
DataGrid1.DataSource = ds
' Bind the data
DataGrid1.DataBind()
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

"Mark" <an*******@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
Can I bind datagrid to an xml string (not to file)? For example, the
result of transformation?


Nov 18 '05 #4
I'm only using a string of XML markup. There's no file involved.
"Mark Goldin" <ma********@comcast.net> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
But how about to bind to a complete xml string (just like you would do
with
the file) but without converting the string into a file first.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:O#**************@TK2MSFTNGP10.phx.gbl...
Hi Mark,

No problem doing what you want to do. Here's one way, there are probably
many others.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' Ken Cox - Microsoft MVP [ASP.NET] Feb 13/04
' Create a stringbuilder to hold the XML
Dim sb As New System.Text.StringBuilder
' Create a dataset to hold the data
Dim ds As New DataSet
' create a TextReader to get the XML
Dim xmlrder As System.Xml.XmlTextReader
' Build some sample XML data (must be well-formed)
sb.Append("<?xml version=""1.0"" standalone=""yes""?>")
sb.Append("<CanadaPostalCodes>")
sb.Append("<Postal_Code>")
sb.Append("<FSA>A0A</FSA>")
sb.Append("<LDA>1A0</LDA>")
sb.Append("<Province>NEWFOUNDLAND AND LABRADOR</Province>")
sb.Append("<Type>Rural</Type>")
sb.Append("<DeliveryInstallation>AQUAFORTE
PO</DeliveryInstallation>")
sb.Append("<Key>1</Key>")
sb.Append("</Postal_Code>")
sb.Append("<Postal_Code>")
sb.Append("<FSA>A0A</FSA>")
sb.Append("<LDA>1B0</LDA>")
sb.Append("<Province>NEWFOUNDLAND AND LABRADOR</Province>")
sb.Append("<Type>Rural</Type>")
sb.Append("<DeliveryInstallation>AVONDALE
PO</DeliveryInstallation>")
sb.Append("<Key>2</Key>")
sb.Append("</Postal_Code>")
sb.Append("</CanadaPostalCodes>")
' Point the xmltextreader to the string full of xml and
' tell it to expect an XML document
xmlrder = New System.Xml.XmlTextReader _
(sb.ToString, System.Xml.XmlNodeType.Document, Nothing)
' Read all of the XML as one chunk
xmlrder.ReadOuterXml()
' Read the outer XML into the Dataset
ds.ReadXml(xmlrder)
' Tell the datagrid to use this dataset
DataGrid1.DataSource = ds
' Bind the data
DataGrid1.DataBind()
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

"Mark" <an*******@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
> Can I bind datagrid to an xml string (not to file)? For example, the
> result of transformation?



Nov 18 '05 #5
Right, but you are appending every node manually.
That's is not what data binding does.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:O8**************@TK2MSFTNGP10.phx.gbl...
I'm only using a string of XML markup. There's no file involved.
"Mark Goldin" <ma********@comcast.net> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
But how about to bind to a complete xml string (just like you would do
with
the file) but without converting the string into a file first.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:O#**************@TK2MSFTNGP10.phx.gbl...
Hi Mark,

No problem doing what you want to do. Here's one way, there are probably many others.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' Ken Cox - Microsoft MVP [ASP.NET] Feb 13/04
' Create a stringbuilder to hold the XML
Dim sb As New System.Text.StringBuilder
' Create a dataset to hold the data
Dim ds As New DataSet
' create a TextReader to get the XML
Dim xmlrder As System.Xml.XmlTextReader
' Build some sample XML data (must be well-formed)
sb.Append("<?xml version=""1.0"" standalone=""yes""?>")
sb.Append("<CanadaPostalCodes>")
sb.Append("<Postal_Code>")
sb.Append("<FSA>A0A</FSA>")
sb.Append("<LDA>1A0</LDA>")
sb.Append("<Province>NEWFOUNDLAND AND LABRADOR</Province>")
sb.Append("<Type>Rural</Type>")
sb.Append("<DeliveryInstallation>AQUAFORTE
PO</DeliveryInstallation>")
sb.Append("<Key>1</Key>")
sb.Append("</Postal_Code>")
sb.Append("<Postal_Code>")
sb.Append("<FSA>A0A</FSA>")
sb.Append("<LDA>1B0</LDA>")
sb.Append("<Province>NEWFOUNDLAND AND LABRADOR</Province>")
sb.Append("<Type>Rural</Type>")
sb.Append("<DeliveryInstallation>AVONDALE
PO</DeliveryInstallation>")
sb.Append("<Key>2</Key>")
sb.Append("</Postal_Code>")
sb.Append("</CanadaPostalCodes>")
' Point the xmltextreader to the string full of xml and
' tell it to expect an XML document
xmlrder = New System.Xml.XmlTextReader _
(sb.ToString, System.Xml.XmlNodeType.Document, Nothing)
' Read all of the XML as one chunk
xmlrder.ReadOuterXml()
' Read the outer XML into the Dataset
ds.ReadXml(xmlrder)
' Tell the datagrid to use this dataset
DataGrid1.DataSource = ds
' Bind the data
DataGrid1.DataBind()
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

"Mark" <an*******@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
> Can I bind datagrid to an xml string (not to file)? For example, the
> result of transformation?


Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pete Nelson | last post by:
Does anyone know of a way to bind a string collection to a datagrid? Basically, I have an object, CreditPlans, and a string collection, ModelNumbers. I'd like to bind the ModelNumbers collection...
4
by: Greg Linwood | last post by:
I am wondering what the best approach to binding XML data to an asp:Table from the Page_Load event in a code behind module? I'm using VB.Net and initially approached this by adding a table to the...
3
by: AFN | last post by:
In VB.NET, I can successfully bind a generic datagrid to a 1 dimensional array. But, now I want to add a button column, and so I think I need to make the first column (the one having data in the...
2
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple...
7
by: Jed | last post by:
I have a web service method that returns an array of custom objects marked serializeable with fully described public properties. When I bind the results to a DataGrid I can access the properties...
2
by: Morten Hauge | last post by:
Hi! I have a problem, I'm not sure if this is the proper way to do it, but I have the following scenario: I want to list all categories, and all products in that category whenever I select a...
1
by: Doug D via .NET 247 | last post by:
I really really need some insight on this problem I am trying to bind a strongly typed collection object to a datagrid. I already Inherited CollectionBase, but .NET says that it cannot find my...
1
by: Øyvind Isaksen | last post by:
I try to make my own ArticleAttribute object and ArticleAttributeCollection, and add data to this Collection. It almost works, but the problem is that each time I add an ArticleAttribute to my...
0
by: pbd22 | last post by:
Hi. I am returning to an old bit of code in our program and need to figure out how to sort my columns on bind. I am sorting on Date (mostly) and some other values. Problem is, the code is an...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.