Display xml file data into gridview using datatable

Posted by Satyapriyanayak under ASP.NET category on | Points: 40 | Views : 3178
Data.xml file

<?xml version="1.0" standalone="yes"?>

protected void btn_showdata_Click(object sender, EventArgs e)

string Path = Server.MapPath("Data.xml");
//student Must match with the element name in your file
DataTable dt = new DataTable("student");

//Add Columns in datatable
//Column names must match XML File nodes
dt.Columns.Add("sid", typeof(System.String));
dt.Columns.Add("sname", typeof(System.String));
dt.Columns.Add("saddress", typeof(System.String));
dt.Columns.Add("smarks", typeof(System.String));

//Read XML File And Display Data in GridView
GridView1.DataSource = dt;

Comments or Responses

Login to post response