1. Other
  2. Other
  3. hi i have a question regarding displaying xml data...

Question: hi i have a question regarding displaying xml data...

Question details

Hi , i have a question regarding displaying xml data in a gridview(asp.net). Im struggling to get it to display all data as each time i go to run it says a error with binding data.

 protected void Data()
        {
            var ds = new DataSet();
            var path = Server.MapPath("~/XMLFile1.xml");
            ds.ReadXml(path);
            GridView1.DataSource = ds;
            GridView1.DataBind();

        }

This is my code and here is the xml:

<?xml version="1.0" encoding="UTF-8"?>

<PurchaseCollection>
  <purchases>
    <Purchase>
      <id>1</id>
      <fullName>Anna Acacia</fullName>
      <emailAddress>anna@acacia.com</emailAddress>
      <productname>Lilly Pilly</productname>
      <unitprice>100</unitprice>
      <quantity>1</quantity>
    </Purchase>
    <Purchase>
      <id>2</id>
      <fullName>Byron Beech</fullName>
      <emailAddress>byron@beech.com</emailAddress>
      <productname>Snow Gum</productname>
      <unitprice>17</unitprice>
      <quantity>2</quantity>
    </Purchase>
    <Purchase>
      <id>3</id>
      <fullName>Cassie Casuarina</fullName>
      <emailAddress>cassie@casuarina.com</emailAddress>
      <productname>Golden Wattle</productname>
      <unitprice>45</unitprice>
      <quantity>3</quantity>
    </Purchase>
    <Purchase>
      <id>4</id>
      <fullName>Donny Dahlia</fullName>
      <emailAddress>donny@dahlia.com</emailAddress>
      <productname>Rusty Gum</productname>
      <unitprice>8</unitprice>
      <quantity>44</quantity>
    </Purchase>
  </purchases>
</PurchaseCollection>


Please any help is welcome as been stuck on it for a while. 

 

 

 

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution