balaji
balaji

Reputation: 1304

How to bind this XML to gridview?

How to bind below XML to Gridview?

<Students>
  <sem id="1">
    <student id="101">
      <mark total="700"/>
    </student>
  </sem>
  <sem id="2">
    <student id="101">
      <mark total="800"/>
    </student>
  </sem>
  <sem id="1">
    <student id="102">
      <mark total="700"/>
    </student>
  </sem>
  <sem id="2">
    <student id="102">
      <mark total="900"/>
    </student>
  </sem>
</Students>

I want to display grid as below

student   sem1  sem2
  101     700   600
  102     800   900

I've tried to read xml into dataset and assigned dataset table to grid source.

Upvotes: 0

Views: 110

Answers (3)

Krishna
Krishna

Reputation: 170

You may use some of the controls from the toolbox :

  • Add the xml file in your project.
  • Add a XMLDataSource in the aspx page.
  • Configure it to refer to the xml file that was added
  • Add the GridView to the aspx page
  • Configure the GridView datasource to refer to the xml data source
  • Then design the GridView to display the fields as per choice.

Upvotes: 0

Leo
Leo

Reputation: 14830

Use the XmlDataSource control an example here

Upvotes: 0

Arpit
Arpit

Reputation: 126

Directly reading the xml file into a dataset may not give you the desired table view. Instead you can use System.Xml namespace and its classes like XmlDocument,XmlElement etc to read the xml and create a datatable and then bind the datasource

Upvotes: 2

Related Questions