Binding DataGrid with XML


Binding DataGrid with XML File:
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.

The DataSet has a ReadXML() method which is used to read data from an XML file.

XML File:


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


DataSet DS = new DataSet();

DS.ReadXml(Server.MapPath("Products1.xml"));

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


Thanks & Regards
Ebook Download
View all
Learn
View all