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.
Florian works as consultant for change- and configuration management for about 7 years. In this environment he is often forced to work with unix, perl and shell scripts.
For more information about change- and configuration management (espacially Serena Dimensions) visit: www.venco.de
For video tutorials about asp.net, ajax, gridviews, ... (in german) visit: www.siore.com