Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am binding a Treeview to an XMLDataSource, The databindings are being generated automaticaly, The XML looks like this:-
<pre>
<Passengers>
<Passenger type="normal" ethnic="asian">
<PassengerName>Name1</PassengerName>
</Passenger>
<Passenger type="normal">
<PassengerName>Name2</PassengerName>
</Passenger>
<Passenger>
<PassengerName>Name3</PassengerName>
</Passenger>
</Passengers>
</pre>


The Treeview displays the XML correctly but when i click on a node and the SelectedNodeChanged event fires the SelectedNode.DataPath is always the path to the first passenger in the list no matter which passenger node i click on.

Does anyone know how to get the datapath of the actual node i click on ?
Posted

1 solution

Couldn't you use the value property of the TreeNode to store the index of each node? You can then track it down using this value.

Good luck!
 
Share this answer
 
Comments
angelvarun 21-Jul-10 4:24am    
Didn't get you exactly..

Below is my code:

XmlDocument objDoc = new XmlDocument();
objDoc.Load(Server.MapPath("AngloMap.xml"));
if (!string.IsNullOrEmpty(TreeView2.SelectedNode.DataPath))
{
XmlNode node = objDoc.SelectSingleNode(TreeView2.SelectedNode.DataPath);
txtEditXML.Text = node.InnerXml;
Session["CurrentEditXpath"] = TreeView2.SelectedNode.DataPath;
}
E.F. Nijboer 21-Jul-10 5:49am    
After loading the xml you could add an index to each node. passenger with name1 would have value 1 and passenger with name2 value 2 and so on. If you then click on the node you can read the index of the node from the value property.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900