473,799 Members | 3,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1640
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.EventArg s) _
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.Str ingBuilder
' Create a dataset to hold the data
Dim ds As New DataSet
' create a TextReader to get the XML
Dim xmlrder As System.Xml.XmlT extReader
' Build some sample XML data (must be well-formed)
sb.Append("<?xm l version=""1.0"" standalone=""ye s""?>")
sb.Append("<Can adaPostalCodes> ")
sb.Append("<Pos tal_Code>")
sb.Append("<FSA >A0A</FSA>")
sb.Append("<LDA >1A0</LDA>")
sb.Append("<Pro vince>NEWFOUNDL AND AND LABRADOR</Province>")
sb.Append("<Typ e>Rural</Type>")
sb.Append("<Del iveryInstallati on>AQUAFORTE
PO</DeliveryInstall ation>")
sb.Append("<Key >1</Key>")
sb.Append("</Postal_Code>")
sb.Append("<Pos tal_Code>")
sb.Append("<FSA >A0A</FSA>")
sb.Append("<LDA >1B0</LDA>")
sb.Append("<Pro vince>NEWFOUNDL AND AND LABRADOR</Province>")
sb.Append("<Typ e>Rural</Type>")
sb.Append("<Del iveryInstallati on>AVONDALE
PO</DeliveryInstall ation>")
sb.Append("<Key >2</Key>")
sb.Append("</Postal_Code>")
sb.Append("</CanadaPostalCod es>")
' Point the xmltextreader to the string full of xml and
' tell it to expect an XML document
xmlrder = New System.Xml.XmlT extReader _
(sb.ToString, System.Xml.XmlN odeType.Documen t, Nothing)
' Read all of the XML as one chunk
xmlrder.ReadOut erXml()
' Read the outer XML into the Dataset
ds.ReadXml(xmlr der)
' Tell the datagrid to use this dataset
DataGrid1.DataS ource = ds
' Bind the data
DataGrid1.DataB ind()
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

"Mark" <an*******@disc ussions.microso ft.com> wrote in message
news:28******** *************** ***********@mic rosoft.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#******** ******@TK2MSFTN GP10.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.EventArg s) _
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.Str ingBuilder
' Create a dataset to hold the data
Dim ds As New DataSet
' create a TextReader to get the XML
Dim xmlrder As System.Xml.XmlT extReader
' Build some sample XML data (must be well-formed)
sb.Append("<?xm l version=""1.0"" standalone=""ye s""?>")
sb.Append("<Can adaPostalCodes> ")
sb.Append("<Pos tal_Code>")
sb.Append("<FSA >A0A</FSA>")
sb.Append("<LDA >1A0</LDA>")
sb.Append("<Pro vince>NEWFOUNDL AND AND LABRADOR</Province>")
sb.Append("<Typ e>Rural</Type>")
sb.Append("<Del iveryInstallati on>AQUAFORTE
PO</DeliveryInstall ation>")
sb.Append("<Key >1</Key>")
sb.Append("</Postal_Code>")
sb.Append("<Pos tal_Code>")
sb.Append("<FSA >A0A</FSA>")
sb.Append("<LDA >1B0</LDA>")
sb.Append("<Pro vince>NEWFOUNDL AND AND LABRADOR</Province>")
sb.Append("<Typ e>Rural</Type>")
sb.Append("<Del iveryInstallati on>AVONDALE
PO</DeliveryInstall ation>")
sb.Append("<Key >2</Key>")
sb.Append("</Postal_Code>")
sb.Append("</CanadaPostalCod es>")
' Point the xmltextreader to the string full of xml and
' tell it to expect an XML document
xmlrder = New System.Xml.XmlT extReader _
(sb.ToString, System.Xml.XmlN odeType.Documen t, Nothing)
' Read all of the XML as one chunk
xmlrder.ReadOut erXml()
' Read the outer XML into the Dataset
ds.ReadXml(xmlr der)
' Tell the datagrid to use this dataset
DataGrid1.DataS ource = ds
' Bind the data
DataGrid1.DataB ind()
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

"Mark" <an*******@disc ussions.microso ft.com> wrote in message
news:28******** *************** ***********@mic rosoft.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********@com cast.net> wrote in message
news:e0******** ******@TK2MSFTN GP10.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#******** ******@TK2MSFTN GP10.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.EventArg s) _
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.Str ingBuilder
' Create a dataset to hold the data
Dim ds As New DataSet
' create a TextReader to get the XML
Dim xmlrder As System.Xml.XmlT extReader
' Build some sample XML data (must be well-formed)
sb.Append("<?xm l version=""1.0"" standalone=""ye s""?>")
sb.Append("<Can adaPostalCodes> ")
sb.Append("<Pos tal_Code>")
sb.Append("<FSA >A0A</FSA>")
sb.Append("<LDA >1A0</LDA>")
sb.Append("<Pro vince>NEWFOUNDL AND AND LABRADOR</Province>")
sb.Append("<Typ e>Rural</Type>")
sb.Append("<Del iveryInstallati on>AQUAFORTE
PO</DeliveryInstall ation>")
sb.Append("<Key >1</Key>")
sb.Append("</Postal_Code>")
sb.Append("<Pos tal_Code>")
sb.Append("<FSA >A0A</FSA>")
sb.Append("<LDA >1B0</LDA>")
sb.Append("<Pro vince>NEWFOUNDL AND AND LABRADOR</Province>")
sb.Append("<Typ e>Rural</Type>")
sb.Append("<Del iveryInstallati on>AVONDALE
PO</DeliveryInstall ation>")
sb.Append("<Key >2</Key>")
sb.Append("</Postal_Code>")
sb.Append("</CanadaPostalCod es>")
' Point the xmltextreader to the string full of xml and
' tell it to expect an XML document
xmlrder = New System.Xml.XmlT extReader _
(sb.ToString, System.Xml.XmlN odeType.Documen t, Nothing)
' Read all of the XML as one chunk
xmlrder.ReadOut erXml()
' Read the outer XML into the Dataset
ds.ReadXml(xmlr der)
' Tell the datagrid to use this dataset
DataGrid1.DataS ource = ds
' Bind the data
DataGrid1.DataB ind()
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

"Mark" <an*******@disc ussions.microso ft.com> wrote in message
news:28******** *************** ***********@mic rosoft.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********@com cast.net> wrote in message
news:e0******** ******@TK2MSFTN GP10.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#******** ******@TK2MSFTN GP10.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.EventArg s) _
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.Str ingBuilder
' Create a dataset to hold the data
Dim ds As New DataSet
' create a TextReader to get the XML
Dim xmlrder As System.Xml.XmlT extReader
' Build some sample XML data (must be well-formed)
sb.Append("<?xm l version=""1.0"" standalone=""ye s""?>")
sb.Append("<Can adaPostalCodes> ")
sb.Append("<Pos tal_Code>")
sb.Append("<FSA >A0A</FSA>")
sb.Append("<LDA >1A0</LDA>")
sb.Append("<Pro vince>NEWFOUNDL AND AND LABRADOR</Province>")
sb.Append("<Typ e>Rural</Type>")
sb.Append("<Del iveryInstallati on>AQUAFORTE
PO</DeliveryInstall ation>")
sb.Append("<Key >1</Key>")
sb.Append("</Postal_Code>")
sb.Append("<Pos tal_Code>")
sb.Append("<FSA >A0A</FSA>")
sb.Append("<LDA >1B0</LDA>")
sb.Append("<Pro vince>NEWFOUNDL AND AND LABRADOR</Province>")
sb.Append("<Typ e>Rural</Type>")
sb.Append("<Del iveryInstallati on>AVONDALE
PO</DeliveryInstall ation>")
sb.Append("<Key >2</Key>")
sb.Append("</Postal_Code>")
sb.Append("</CanadaPostalCod es>")
' Point the xmltextreader to the string full of xml and
' tell it to expect an XML document
xmlrder = New System.Xml.XmlT extReader _
(sb.ToString, System.Xml.XmlN odeType.Documen t, Nothing)
' Read all of the XML as one chunk
xmlrder.ReadOut erXml()
' Read the outer XML into the Dataset
ds.ReadXml(xmlr der)
' Tell the datagrid to use this dataset
DataGrid1.DataS ource = ds
' Bind the data
DataGrid1.DataB ind()
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

"Mark" <an*******@disc ussions.microso ft.com> wrote in message
news:28******** *************** ***********@mic rosoft.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******** ******@TK2MSFTN GP10.phx.gbl...
I'm only using a string of XML markup. There's no file involved.
"Mark Goldin" <ma********@com cast.net> wrote in message
news:e0******** ******@TK2MSFTN GP10.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#******** ******@TK2MSFTN GP10.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.EventArg s) _
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.Str ingBuilder
' Create a dataset to hold the data
Dim ds As New DataSet
' create a TextReader to get the XML
Dim xmlrder As System.Xml.XmlT extReader
' Build some sample XML data (must be well-formed)
sb.Append("<?xm l version=""1.0"" standalone=""ye s""?>")
sb.Append("<Can adaPostalCodes> ")
sb.Append("<Pos tal_Code>")
sb.Append("<FSA >A0A</FSA>")
sb.Append("<LDA >1A0</LDA>")
sb.Append("<Pro vince>NEWFOUNDL AND AND LABRADOR</Province>")
sb.Append("<Typ e>Rural</Type>")
sb.Append("<Del iveryInstallati on>AQUAFORTE
PO</DeliveryInstall ation>")
sb.Append("<Key >1</Key>")
sb.Append("</Postal_Code>")
sb.Append("<Pos tal_Code>")
sb.Append("<FSA >A0A</FSA>")
sb.Append("<LDA >1B0</LDA>")
sb.Append("<Pro vince>NEWFOUNDL AND AND LABRADOR</Province>")
sb.Append("<Typ e>Rural</Type>")
sb.Append("<Del iveryInstallati on>AVONDALE
PO</DeliveryInstall ation>")
sb.Append("<Key >2</Key>")
sb.Append("</Postal_Code>")
sb.Append("</CanadaPostalCod es>")
' Point the xmltextreader to the string full of xml and
' tell it to expect an XML document
xmlrder = New System.Xml.XmlT extReader _
(sb.ToString, System.Xml.XmlN odeType.Documen t, Nothing)
' Read all of the XML as one chunk
xmlrder.ReadOut erXml()
' Read the outer XML into the Dataset
ds.ReadXml(xmlr der)
' Tell the datagrid to use this dataset
DataGrid1.DataS ource = ds
' Bind the data
DataGrid1.DataB ind()
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]

"Mark" <an*******@disc ussions.microso ft.com> wrote in message
news:28******** *************** ***********@mic rosoft.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
2102
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 to the datagrid, but because there isn't a custom object with properties, just a string object, I'm not sure how to reference it in the datagrid. FYI, I can enumerate through the collection... foreach(string modelNum in...
4
4092
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 web page from the VS2003 ASP page designer, extracting an XML document from SQL Server during Page_Load, then adding asp:TableRows & asp:TableCells one at a time / loading the corresponding xml values a cell at a time. Is there a better (less...
3
1952
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 array) a "BoundColumn" and the 2nd column my button column. The problem is that the BoundColumn wants a DataField name. There is none! So how do I bind this one column to the array column when the array doesn't have column names? And if your...
2
2209
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 properties, ProdID, Description, Quantity and UPC. 3 strings and a long. The LineItemsCollection class inherits from System.Collections.Specialized.NameObjectCollectionBase. It also implements both IEnumerable and IList.
7
2565
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 in the ItemDataBound event of the codebehind but I can't access them declaratively in the HTML code? Here is the code to call the method. net.mysite.www.WSInterface proxy; proxy = new net.mysite.www.WSInterface();
2
1352
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 topcategory in a menu. Example: - Music
1
2953
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 property name, when I try to bind it to the grid.. now, here is where it gets tricky. Do I NEED to Implement IBindingList, on my collection object, since my object that I am adding to the collection inherits from a another class? here is my...
1
1341
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 Collection, it seems like it overwrites the other ArticleAttributes. When bind the ArticleAttributeCollection to a datagrid, all articleattributes are the same. This is what my datagrid dispays: ID Content
0
1245
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 ArrayList that seems to do some tricky stuff with a chache object and I am unable to get any sort of sorting happening.
0
9686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.