Signup · Login
Stardeveloper.com  
Home · Articles · Forums · Advertise · Contact
Article Categories
.NET  .NET
  ASP (15)
  ASP.NET (26)
  ADO (16)
  ADO.NET (10)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)
Latest Forum Activity
what is the right code to link the asp page t..
by amylisa on 22 Jul 2008 Go To Post

Can Loader.asp Get Form Elements
by azziham on 14 Jul 2008 Go To Post

Good asp resource sites
by codemylife on 3 Jul 2008 Go To Post

Re: Unable to insert data in an Access databa..
by asia on 3 Jul 2008 Go To Post

Re: problem with do while loop
by idsanjeev on 30 Jun 2008 Go To Post

Log In
UserName Or Email:

Password:

Auto-Login:

Miscellaneous Links
  Submit Article

Hosted by Securewebs.com
 
Home : .NET : ASP.NET : Displaying XML Data in an ASP.NET page : Binding DataGrid to an XML File
 

Displaying XML Data in an ASP.NET page : Binding DataGrid to an XML File
by Sriram Vaideeswaran.

Overview :
The .net framework provides the Dataset object which is designed to handle data abstractly independent of the data source. The DataSet can handle data from variety of sources like SQL, XML etc. In this article we'll show you how to bind a data grid control to data in an XML file using the DataSet class.

In order access the DataSet class you must import the System.Data namespace into your page.

<% @ Import NameSpace = "System.Data" %>

The DataSet has a ReadXML() method which is used to read data from an XML file. For a DataSet to correctly read data from an XML file, the XML file should be of the following format :

<RootElement>
<TableName>
    <FieldName1>Field value</FieldName1>
    <FieldName2>Field value</FieldName2>
    <FieldName3>Field value</FieldName3>
    <FieldName4>Field value</FieldName4>
</TableName>
<TableName>
    <FieldName1>Field value</FieldName1>
    <FieldName2>Field value</FieldName2>
    <FieldName3>Field value</FieldName3>
    <FieldName4>Field value</FieldName4>
</TableName>
......
</RootElement>

Where each TableName section represents a row of data from the table.

Example :

<ProductList>
	<Products>
		<ProductId>1</ProductId>
		<ProductName>Rice</ProductName>
		<Rate>27</Rate>
	</Products>
	<Products>
		<ProductId>2</ProductId>
		<ProductName>Wheat</ProductName>
		<Rate>20</Rate>
	</Products>
</ProductList>

The name of the XML file along with the full path is passed as an argument to the ReadXml method of the DataSet.

DataSet DS = new DataSet();
DS.ReadXml(Server.MapPath("Products1.xml"));

The DataSet can then be bound to the DataGrid using the DataBind() method of the DataGrid.

DG1.DataSource = DS;
DG1.DataBind();

 ( No Further Pages )

Download Associated Files
002E.Zip

Comments/Questions ( Threads: 2, Comments: 2 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. Problem in reading XML by making a webrequest asyncronously
  2. reading xml tags

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed.

 
© 1999 - 2008 Stardeveloper.com, All Rights Reserverd.