Friday, March 13, 2009

How XML Data to Datagrid

The following code extracts data from the xml (EmpData) and displays in a Datagrid. The xml data resides in a separate directory. The Mappath method is used to map xml data correctly to the application. The DataBind method of the DataGrid (dgEmployee) is used to display the data from the dataset dsEmp.

The following shows the xml content in xmldata/Empdata.xml. Here, xmldata is the directory within the virtual path and Empdata.xml is the xml data file.

E00001
STEVE
ROBERTS
HUMAN RESOURCE


E00002
JOHN
GRAY
PROJECTS
The following code will display the xml data into the datagrid:


DataSet dsEmp = new DataSet();
dsEmp.ReadXml(MapPath("xmldata/Empdata.xml"));
dgEmployee.DataSource=dsEmp;
dgEmployee.DataBind();

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home