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

Discussion in 'ASP .Net Web Controls' started by placek, Mar 27, 2006.

  1. placek

    placek Guest

    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.
     
    placek, Mar 27, 2006
    #1
    1. Advertising

  2. placek

    misiek Guest

    Anybody?
     
    misiek, Mar 29, 2006
    #2
    1. Advertising

  3. placek

    Guest

    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.
     
    , Mar 29, 2006
    #3
  4. placek

    misiek Guest

    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
     
    misiek, Mar 29, 2006
    #4
  5. placek

    Guest

    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.
     
    , Mar 29, 2006
    #5
  6. placek

    misiek Guest

    I did not know that it is so simple!

    Thanks a lot, Caffiene.

    Best regards
     
    misiek, Mar 30, 2006
    #6
  7. placek

    Guest

    My pleasure.
     
    , Mar 30, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VHltYm93?=
    Replies:
    2
    Views:
    24,490
    =?Utf-8?B?VHltYm93?=
    Jan 10, 2006
  2. =?Utf-8?B?RGljaw==?=

    ObjectDataSource's underlying data/schema

    =?Utf-8?B?RGljaw==?=, Mar 1, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,772
    Steven Cheng[MSFT]
    Mar 1, 2006
  3. velthuijsen
    Replies:
    2
    Views:
    340
    velthuijsen
    Nov 18, 2004
  4. Curious Trigger
    Replies:
    4
    Views:
    7,228
    Curious Trigger
    Jul 24, 2006
  5. djc
    Replies:
    2
    Views:
    169
Loading...

Share This Page