I have an ASP site with a dataset and gridview, which I want to display XML data.
The gridview is not automatically generated, and is set to find hotelid, name, status, city & country.
Currently, I have written the XML manually, however I have included wrapper tags and additional error tags that will be required in this XML but whenever they are included, an error shows up saying the gridview was unable to find “HOTEL_ID” property. It works fine without the additional data.
XML example:
<REQUEST><ACTION>HOTEL_LIST</ACTION><RESPONSE><RESULT>0</RESULT>
<HOTELS>
<HOTEL><HOTELID>hot01</HOTELID><NAME>hotel test 1</NAME><CITY>birmingham</CITY><COUNTRY>england</COUNTRY><STATUS>active</STATUS></HOTEL>
<HOTEL><HOTELID>hot02</HOTELID><NAME>hotelabctestabc2abc</NAME><CITY>barca</CITY><COUNTRY>spain</COUNTRY><STATUS>inactive</STATUS></HOTEL>
<HOTEL><HOTELID>hot03</HOTELID><NAME>hotelabctestabcire</NAME><CITY>dublin</CITY><COUNTRY>ireland</COUNTRY><STATUS>active</STATUS></HOTEL>
</HOTELS>
<ERRORS><ERROR><CODE></CODE><MESSAGE></MESSAGE></ERROR></ERRORS></RESPONSE></REQUEST>`
and Here is the VB Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim teststring As String = "THE XML SHOWN ABOVE"
Dim ds As New DataSet()
Dim doc As New XmlDocument()
doc.LoadXml(teststring)
ds.ReadXml(New System.IO.StringReader(doc.OuterXml))
GridView1.DataSource = ds
GridView1.DataBind()
End Sub
`
If I remove leave only the only hotel info, it works and finds the property;
<HOTELS><HOTEL><HOTELID>hot01</HOTELID><NAME>hotel test 1</NAME><CITY>birmingham</CITY><COUNTRY>england</COUNTRY><STATUS>active</STATUS></HOTEL>
<HOTEL><HOTELID>hot02</HOTELID><NAME>hotelabctestabc2abc</NAME><CITY>barca</CITY><COUNTRY>spain</COUNTRY><STATUS>inactive</STATUS></HOTEL><HOTEL>
<HOTELID>hot03</HOTELID><NAME>hotelabctestabcire</NAME><CITY>dublin</CITY><COUNTRY>ireland</COUNTRY><STATUS>active</STATUS></HOTEL></HOTELS>
What am I doing wrong?
Thanks.
When you are loading an XML document like that into a DataSet, it creates multiple tables based on the data.
In order to bind only the Hotel info to your GridView, you will need to identify which table in the dataset contains the data and then bind this to the GridView
e.g.
Hope that helps.