Binding Xml Data into Gridview using C#

Hi, I have a XML file which contains a list of items/elements:

<Trail category="Zoo" ID="001">
		<Name>Cat Country</Name>
		<Description>Caracal, Jaguar, Leopard, Mountain Lion</Description>
		<Latitude>1.2345</Latitude>
		<Longtitude>2.3445</Longtitude>
	</Trail>

	<Trail category="Zoo" ID="002">
		<Name>Wild Africa</Name>
		<Description>African Lion, Cheetah, Giraffe, White Rhinoceros, Zebra, African hunting dog, Banded Mongoose</Description>
		<Latitude>1.98548</Latitude>
		<Longtitude>110.305677</Longtitude>
	</Trail>
<Trail category="Jurong Bird Park" ID="003">
		<Name>Flightless Birds</Name>
		<Description>Ostriches, Emus, Rheas, Cassowaries</Description>
		<Latitude>100.457268</Latitude>
		<Longtitude>50.215818</Longtitude>
	</Trail>

	<Trail category="Jurong Bird Park" ID="004">
		<Name>World of Darkness</Name>
		<Description>Night Herons, Fish Owls, Snowy Owls</Description>
		<Latitude>105.466856</Latitude>
		<Longtitude>59.245538</Longtitude>
	</Trail>

I can bind the data into a gridview. However, only the attributes are displayed(which is: category and ID). I need the elements to display out too (which is: Name,Description,Latitude and Longtitude).

Would anyone be kind enough to solve this problem for me?

And is it possible to populate a drop down list in using the same XML file? As in populating the category in the drop down list.

Thanks alot. :slight_smile:

Yes it is possible. We can help you if you give us the code you are using to bind

Thanks. I am now able to populate the XML data into the drop down list and has enable autopostback.

But no action taken place because I still can’t get the elements out from the xml file into the gridview.
I’m actually using XMLDataSource where the data file is kept at ~/App_Data/Trail.xml . The XPath Expression is /GIS/Trail. I’m not sure if this XPath Expression is correct. Please correct me if I’m wrong.

I need the XML data to be display like this in the gridview:


<table>
<tr>
<td>name</td>
<td>description</td>
<td>Latitude</td>
<td>Longtitude</td>
</tr>

<tr>
<td>Cat Country</td>
<td>Caracal, Jaguar, Leopard, Mountain Lion</td>
<td>1.2345</td>
<td>2.3445</td>
</tr>

<tr>
<td>Wild Africa</td>
<td>African Lion, Cheetah, Giraffe, White Rhinoceros, Zebra, African hunting dog, Banded Mongoose</td>
<td>1.98548</td>
<td>110.305677</td>
</tr>

<tr>
<td>Sea Lion Show</td>
<td>Burmese Python, California Sea Lione</td>
<td>1.105056</td>
<td>105.2684125</td>
</tr>
</table>

Can you help me with this problem?

Many thanks. :slight_smile: