How to fill Grid from XML file ?


Hi

For doing this task create a Emp.xml file like this

<?xml version=”1.0″ encoding=”utf-8″?>
<Emps>
<Emp Id=”1″>
<EmpName>werwer</EmpName>
<EmpSal>345345</EmpSal>
</Emp>
<Emp Id=”2″>
<EmpName>Ram</EmpName>
<EmpSal>45000</EmpSal>
</Emp>
<Emp Id=”3″>
<EmpName>Hari</EmpName>
<EmpSal>35000</EmpSal>
</Emp>
</Emps>

Step2: Write the code in Code behind file like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class GridFillXML : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string filePath = Server.MapPath(“Emp.xml”);
using (DataSet ds = new DataSet())
{
ds.ReadXml(filePath);
GridView1.DataSource = ds;
GridView1.DataBind();
}

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: