XML to Datagrid

To display the data in a DataGrid you can do this:

Code:
Imports System.Xml
Imports System.Data
Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Put user code to initialize the page here
        If Not Me.IsPostBack Then
            Dim dataXML As New XmlDataDocument()
            dataXML.DataSet.ReadXmlSchema(Server.MapPath("Catalog.xsd"))
            dataXML.Load(Server.MapPath("catalog.xml"))
            DataGrid1.DataSource = dataXML.DataSet.Tables(0)
            DataGrid1.DataBind()
        End If
    End Sub

You can create the .xsd file automatically. Select the XML file and on the main menu choose XML>>Create Schema.
 
Last edited by a moderator:
I dont want to connect over a server, I have xml files stored in the application directory on local computer, and just want to display the data in a datagrid.

Just want:

ID NAME SURNAME
1 John Davies
2 Tom Jones

etc
 
Back
Top