The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
Sometimes you want to use an XML file rather than a database to store your information. Maybe you don't have a database at your hosting account or you have mostly static data. This article explains how to bind an XML file to a
GridView in four lines of code.
The XML File
First, create a new XML file and populate it with some data. Here is an example:
Bind the XML File to a GridView
GridView control on to your web form. Next, you need some code to bind the data from the XML file to your
Partial Class _Default
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
Dim oDs As New DataSet
oDs.ReadXml(Request.PhysicalApplicationPath + "XMLFile.xml")
GridView1.DataSource = oDs
Page_Load event, we create a new
DataSet and use the method
ReadXml to get the data from the XML file. Then we bind the
DataSet to the
Points of Interest
In order to avoid "hard coding" the path to the XML file , I use
Request.PhysicalApplicationPath to specify the location of the file.