bind xml to gridview

Posted by Saratvaddilli under C# on 3/25/2013 | Points: 10 | Views : 2122 | Status : [Member] [MVP] | Replies : 5
hi all ,
i had an xml , i want to bind name to grid-view header and values under the name


<row>
<var name="&quot;ConcessionaryName&quot;" value="&quot;L&amp;T&quot;" />
<var name="&quot;CountOfRecords&quot;" value="1" />
<var name="&quot;Amount&quot;" value="&quot;Rs.25.00&quot;" />
<var name="&quot;FileName&quot;" value="&quot;ConcessionaireSettlement_24012013&quot;" />
<var name="&quot;Status&quot;" value="&quot;Generated&quot;" />
<var name="&quot;Date&quot;" value="12/12/12" />
</row>


i want to bind name to gridview header and value to gridview items

Please see the attached image for required output

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are



Responses

Posted by: Jayakumars on: 3/25/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
try his code


DataTable dt = new DataTable();
dt.ReadXml(Server.MapPath("Test.xml"));


Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Saratvaddilli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saratvaddilli on: 3/25/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
it will not fulfill my requirement , just binding is not enough it should bind name to header and values as items in the gridview

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Saratvaddilli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/25/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

post your xml file.

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Saratvaddilli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saratvaddilli on: 3/25/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<root>
<row>
<var name="&quot;ConcessionaryName&quot;" value="&quot;L&amp;T&quot;" />
<var name="&quot;CountOfRecords&quot;" value="1" />
<var name="&quot;Amount&quot;" value="&quot;Rs.25.00&quot;" />
<var name="&quot;FileName&quot;" value="&quot;ConcessionaireSettlement_24012013&quot;" />
<var name="&quot;Status&quot;" value="&quot;Generated&quot;" />
<var name="&quot;Date&quot;" value="12/12/12" />
</row>
<row>
<var name="&quot;ConcessionaryName&quot;" value="&quot;Soma&quot;" />
<var name="&quot;CountOfRecords&quot;" value="2" />
<var name="&quot;Amount&quot;" value="&quot;Rs.3176.00&quot;" />
<var name="&quot;FileName&quot;" value="&quot;ConcessionaireSettlement_24012013&quot;" />
<var name="&quot;Status&quot;" value="&quot;Generated&quot;" />
<var name="&quot;Date&quot;" value="13/12/12" />
</row>
<row>
<var name="&quot;ConcessionaryName&quot;" value="&quot;GMR&quot;" />
<var name="&quot;CountOfRecords&quot;" value="3" />
<var name="&quot;Amount&quot;" value="&quot;Rs.4171.00&quot;" />
<var name="&quot;FileName&quot;" value="&quot;ConcessionaireSettlement_24012013&quot;" />
<var name="&quot;Status&quot;" value="&quot;Generated&quot;" />
<var name="&quot;Date&quot;" value="14/12/12" />
</row>
<row>
<var name="&quot;ConcessionaryName&quot;" value="&quot;Jaypee&quot;" />
<var name="&quot;CountOfRecords&quot;" value="22" />
<var name="&quot;Amount&quot;" value="&quot;Rs.8575.00&quot;" />
<var name="&quot;FileName&quot;" value="&quot;ConcessionaireSettlement_24012013&quot;" />
<var name="&quot;Status&quot;" value="&quot;Generated&quot;" />
<var name="&quot;Date&quot;" value="15/12/12" />
</row>
<row>
<var name="&quot;ConcessionaryName&quot;" value="&quot;sarat&quot;" />
<var name="&quot;CountOfRecords&quot;" value="22" />
<var name="&quot;Amount&quot;" value="&quot;Rs.8575.00&quot;" />
<var name="&quot;FileName&quot;" value="&quot;ConcessionaireSettlement_24012013&quot;" />
<var name="&quot;Status&quot;" value="&quot;Generated&quot;" />
<var name="&quot;Date&quot;" value="15/12/12" />
</row>
</root>

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Saratvaddilli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 3/25/2013 [Member] Starter | Points: 25

Up
0
Down
hi
Try this ithink it is useful to you
In XMl file
<?xml version="1.0" encoding="utf-8" ?>
<Employee>
<Emp>
<Empid>1</Empid>
<EmpName>aswini</EmpName>
</Emp>
<Emp>
<Empid>2</Empid>
<EmpName>aluri</EmpName>
</Emp>
</Employee>

and in .aspx.cs page

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getdata();
}

}
public void getdata()
{
XmlTextReader xtr = new XmlTextReader(Server.MapPath("XMLFile1.xml"));
DataSet dt = new DataSet();
dt.ReadXml(xtr);
xtr.Close();
if (dt.Tables.Count != 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}

Thanks & Regards
Aswini Aluri

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Saratvaddilli, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response