ASP.NET TreeView and XML Arrays

I bind TreeView to XMLDataSource, data files are generated automatically and XML looks like: -

<Passengers>
  <Passenger>
    <PassengerName>Name1</PassengerName>
  </Passenger>
  <Passenger>
    <PassengerName>Name2</PassengerName>
  </Passenger>
  <Passenger>
    <PassengerName>Name3</PassengerName>
  </Passenger>
</Passengers>

      

The TreeView displays the XML correctly, but when I click on a node and the SelectedNodeChanged event calls SelectedNode.DataPath, it is always the path to the first passenger in the list, no matter which passenger node I click.

Does anyone know how to get the datapath of the actual node I clicked on?

+1


source to share


3 answers


from here I think he cannot distinguish between passenger units. they do not seem to have their own identifier. checking out the help for binding the tree structure at the time I return.



The hint helper says you can customize how and what you bind to your xmldatasource with which node properties. you might be missing the navigateurl value and properties in your binding.

+1


source


I believe in a tree using a value to be provided to navigate the value path. Only then can you navigate the trail. Also, not sure, but I thought the XmlDataSource liked to use attributes instead of child elements to describe the entity values ​​as well, so that might be a problem too ...



+1


source


You probably need to identify each node with an id

<Passengers>
  <Passenger Id="Passenger1">
    <PassengerName>Name1</PassengerName>
  </Passenger>
  <Passenger Id="Passenger2">
    <PassengerName>Name2</PassengerName>
  </Passenger>
  <Passenger Id="Passenger3">
    <PassengerName>Name3</PassengerName>
  </Passenger>
</Passengers>

      

+1


source







All Articles