Posts tagged: dataset readxml

Oct 07 2009

display xml data in gridview

I explained already how to save form data into xml file in previous

article you can click this link to navigate to that article.

Save form data into xml file

how to display xml data into gridview using dataset

Reads XML schema and data into the DataSet using the specified

System.IO.Stream.

ReadXml method is used to fill it with schema and data.

Steps  to display xml data into gridview
step1: Open visual studio –> File –> New –> Website –>choose

visual studio template asp.net website–>ok

step2: order.xml file data

<?xml version=”1.0″?>
<orderReport>

<report>
<orderCode>1234</orderCode>
<Date>21321</Date>
<Location>dada</Location>
<Content>asad</Content>
<Count>12</Count>
</report>

<report>
<orderCode>1002</orderCode>
<Date>09-02-2009</Date>
<Location>chennai</Location>
<Content>plasma</Content>
<Count>5</Count>
</report>

<report>
<orderCode>1003</orderCode>
<Date>06-03-2008</Date>
<Location>pune</Location>
<Content>Bikes</Content>
<Count>10</Count>
</report>

</orderReport>

step3: Drag the Gridview control into default.aspx page then write

the code in page_load event to display xml data into gridview.

display form data

display form data

Note:1) my xml file name is order.xml it doesn’t

contain any    folders.so give the path as

Server.MapPath(”order.xml”)

2) If the order.xml inside the folder name of

orderDetails then change the path as

Server.MapPath(”orderDetails/order.xml”)

sample code look like in Default.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{

DataSet objDs = new DataSet();

//it does not contain any folder
objDs.ReadXml(Server.MapPath(”order.xml“));

//Inside orderDetails is foldername contain order.xml file
//objDs.ReadXml(Server.MapPath(”orderDetails/order.xml”));

GridView1.DataSource = objDs;
GridView1.DataBind();
}

Alibi3col theme by Themocracy