Blade
Blade

Reputation: 394

Binding xml document to gridview doesn't work

I have an XML document which looks like this:

<xconnect>
<type>OK</type>
<response/>
<report>
    <id>suppressionlist_get</id>
    <name>Suppression List Get</name>
    <timestamp>24 Oct 08 @ 10:16AM</timestamp>
    <records type=\"user\"/>
    <records type=\"client\"/>
    <records type=\"group\">
        <record>
            <email>[email protected]</email>
            <type>RECIPSELF</type>
            <long_type>Recipient self suppressed</long_type>
            <created>23 Oct 08 @ 8:53PM</created>
            <user>facm</user>
        </record>

I have omitted the closing of the document for clarity and to keep this post short.

Anyway, I have a GridView and I want to bind this XML to the GridView so I get table, like:

email | type | long | created | user
------------------------------------
data    data   data    data     data

And so forth.

I was playing with DataSets and XMLDataDocuments and when stepping through, each attribute seemed to be represented as its own table in a data collection table.

Any ideas on how to achieve the above? I thought it was as simple as just adding a GridView, and XML data source with the data file specified.

Thanks

Upvotes: 1

Views: 1727

Answers (2)

jon3laze
jon3laze

Reputation: 3196

Try:

DataSet dataSet = new DataSet();
dataSet.ReadXML("Path to XML");
this.GridView1.DataMember = "record";
this.GridView1.DataSource = dataSet;
this.GridView1.DataBind();

Upvotes: 1

benPearce
benPearce

Reputation: 38333

Create a test DataSet and write it out to Xml to get a feel for the Xml format used by a dataset, then either convert the Xml format to match this and then load it in to the Dataset using DataSet.LoadXml().

Or you could build a DataSet on the fly from your existing Xml format.

Upvotes: 0

Related Questions