Steps:
1. Declare a dataset.
2. Take string variable and call the ‘mapPath’ method of Server object and pass the xml file name as parameter.
3.Create new instance of dataset.
4.Read xml file using ‘ReadXml’ method of dataset and pass the string variable.
5.Now set the ‘datasource’ property of ‘Gridview’.
6.Bind the data to ‘gridview’.
Write the following code in the event where you want to load gridview.
//code for reading and binding gridview with xml file.
DataSet dsExample;
string filePath = Server.MapPath("example.xml");
dsExample = new DataSet();
dsExample.ReadXml(filePath);
gvExample.DataSource = dsExample.Tables[0].DefaultView;
gvExample.DataBind();
1. Declare a dataset.
2. Take string variable and call the ‘mapPath’ method of Server object and pass the xml file name as parameter.
3.Create new instance of dataset.
4.Read xml file using ‘ReadXml’ method of dataset and pass the string variable.
5.Now set the ‘datasource’ property of ‘Gridview’.
6.Bind the data to ‘gridview’.
Write the following code in the event where you want to load gridview.
//code for reading and binding gridview with xml file.
DataSet dsExample;
string filePath = Server.MapPath("example.xml");
dsExample = new DataSet();
dsExample.ReadXml(filePath);
gvExample.DataSource = dsExample.Tables[0].DefaultView;
gvExample.DataBind();
How to bind xml file to gridview.
Reviewed by kamal kumar das
on
October 24, 2011
Rating:
No comments: