rahul aggarwal
rahul aggarwal

Reputation: 265

Reading XML with sub child in asp.net

My XML is in following format.

 <Test1>
<Test>

<Name>A</Name>
<Image>~/FltImages/DL.gif</Image>
<Fare>1243.8</Fare>

<OutbondInfo>
<Duration>0900</Duration>
<Type>Non-Stop</Type>

<Sector>

<Name>A</Name>
<Image>~/FltImages/DL.gif</Image>
<No>4410</No>
<AirCraftNo>744</AirCraftNo>
<CabinClass Name="ECONOMY">M</CabinClass>
</Sector>
</OutbondInfo>

<InboundInfo>
<Duration>0805</Duration>
<Type>Non-Stop</Type>
<Sector>
<Name>A</Name>
<Image>~/FltImages/DL.gif</Image>
<No>4410</No>
<AirCraftNo>744</AirCraftNo>
<CabinClass Name="ECONOMY">M</CabinClass>
</Sector>
</InboundInfo>

<Type>IT</Type>
</Test>
</Test1>

I am reading the detail as follows, but my code doesn't read the code under OutbondInfo and InbondInfo. How can I read data under those tags and save in same DataSet as shown in code below.

XmlNode xNode;
xNode = fc.gettDetail(TextBox1.Text);
DataSet ds = new DataSet();
if (xNode != null)
{
    XmlTextReader xmlTextReader = new XmlTextReader(xNode.OuterXml, XmlNodeType.Element, null);
    ds.ReadXml(xmlTextReader);
    GridView1.DataSource = ds;
    GridView1.DataBind();
}

Please Help!!

Thanks

Upvotes: 1

Views: 88

Answers (1)

afzalulh
afzalulh

Reputation: 7943

Your DataSet is returning multiple table. You can select only one table to bind to a gridview. Here's how your DataSet looks:

enter image description here

Solution: For each table use separate GridView. Bind GridViews like below:

 GridView1.DataSource = ds.Tables["OutbondInfo"];
 GridView1.DataBind();
 //Add another GridView "GridView2" in markup
 GridView2.DataSource = ds.Tables["InboundInfo"];
 GridView2.DataBind();

Hope it helps!

Upvotes: 1

Related Questions