Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > How to get underlying data of TreeView control? (ASP.NET 2.0)

Reply
Thread Tools

How to get underlying data of TreeView control? (ASP.NET 2.0)

 
 
placek
Guest
Posts: n/a
 
      03-27-2006
Hi all.

I have a page with a TreeView control and a XmlDataSource. I set
XmlDataSource.Data property with some DataSet.GetXML() method and then
I programatically set TreeView.DataSourceId to my XmlDataSource. It
works fine, all data is properly displayed. One more thing: this
TreeView control is placed in WizardControl.

My problem starts when user clicks Next button in WizardControl. At
this moment I would like to retrieve underlying data of my TreeView
control. Unfortunately, TreeView.DataSource seems to be null.

I tried to store XmlDataSource.Data in Session at the moment, when data
is bound, but this approach is not good for me. The reason is that it
stores initial data values. In fact I need to retrieve current data
values. Why? Because user could for example (un)check some checkboxes
from TreeView and I would like to know about that. I know, that there
is a TreeView.CheckedNodes property, but I need to retrieve ALL
structure, not only changed nodes.

Is there some way to retrieve TreeView data, which is currently
displayed in browser?

My second problem is how to find some node in XML file, when I iterate
through TreeView.CheckedNodes collection. I know that there is a
GetElementById() method of XmlDocument, but I have no idea how to get
node id from some node.

Does anybody can help me?

Thanks in advance,
misiek.

 
Reply With Quote
 
 
 
 
misiek
Guest
Posts: n/a
 
      03-29-2006
Anybody?

 
Reply With Quote
 
 
 
 
CaffieneRush@gmail.com
Guest
Posts: n/a
 
      03-29-2006
For your first problem. I don't believe the treeview supports 2 way
databinding - its only one way from data source control or object to
the treeview but not back. Besides you either associate your treeview
to a data source control (like XMLDataSource) using the DataSourceID
property or a data object (like DataSet) using the DataSource property
but not both.
You'll need to work with the treeview directly on the postback but I
might be wrong.

For your second problem. There is no node id property within treenode,
unless of course you subclass treenode and provide an id.
What I do is use the name or value property of treenode to locate the
node within the tree. Of course that assumes that the text and value
are unique to each node.

Eg. find the node by text.

Public Function GetNodeByText(ByVal text As String) As MyTreeNode
Return GetNodeByText(text, Nodes)
End Function

Public Function GetNodeByText(ByVal text As String, ByVal childNodes As
TreeNodeCollection) As MyTreeNode

Dim node As MyTreeNode

For Each node In childNodes
'Search immediate children first
If node.Text = text Then
'Found node with matching text.
Exit For
End If

'If children themselves have children then search those
as well
If node.ChildNodes.Count > 0 Then
Return GetNodeByText(text, node.ChildNodes)
End If
Next

Return node

End Function

Hope that helps.

 
Reply With Quote
 
misiek
Guest
Posts: n/a
 
      03-29-2006
HI Caffiene.

Thanks for the answer.

Unfortunately Text value of some of my nodes could be the same.
However, they could be distinguished by some attribute value:
every node has QUSTION_ID attribute, which is unique. On the other side
I do not display value of that attribute.

Is there some way to compare nodes based on this attribute?

Best regards,
placek

 
Reply With Quote
 
CaffieneRush@gmail.com
Guest
Posts: n/a
 
      03-29-2006
I can't see a problem with finding nodes by the QUESTION_ID attribute.

Public Function GetNodeByQID(ByVal QID As String) As MyTreeNode
Return GetNodeByQID(QID, Nodes)
End Function

Public Function GetNodeByQID(ByVal QID As String, ByVal childNodes As
TreeNodeCollection) As MyTreeNode

Dim node As MyTreeNode

For Each node In childNodes
'Search immediate children first
If node.Attributes("QUESTION_ID") = QID Then
'Found node with matching text.
Exit For
End If

'If children themselves have children then search those
as well
If node.ChildNodes.Count > 0 Then
Return GetNodeByQID(QID, node.ChildNodes)
End If
Next

Return node

End Function

Regards.

 
Reply With Quote
 
misiek
Guest
Posts: n/a
 
      03-30-2006
I did not know that it is so simple!

Thanks a lot, Caffiene.

Best regards

 
Reply With Quote
 
CaffieneRush@gmail.com
Guest
Posts: n/a
 
      03-30-2006
My pleasure.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to get more data from a gridview's underlying datasource? Curious Trigger ASP .Net 4 07-24-2006 06:17 PM
ObjectDataSource's underlying data/schema =?Utf-8?B?RGljaw==?= ASP .Net 2 03-01-2006 08:26 AM
how to get to the underlying data in a datagrid control? djc ASP .Net Datagrid Control 2 12-17-2004 02:11 PM
How do I use two different class interfaces to the same underlying data? velthuijsen C++ 2 11-18-2004 08:03 AM



Advertisments