Problem to get/set Value with RadTreeView

3 posts, 0 answers
  1. Daniel
    Daniel avatar
    159 posts
    Member since:
    Feb 2014

    Posted 23 Mar 2014 Link to this post

    Hi
    I'm trying to use the RadTreeView like this:
    the treeView takes its data from a list.
    When I press on a node, I get a value from it (& then later I can call function base on the value)

    I have a hard time to set value into the treeView

    I set the List like that:
    vb.NET:
    01.Friend Class SiteDataItem
    02.     Private text1 As String
    03.     Private id1 As Integer
    04.     Private parentId1 As Integer
    05.     Private report_id1 As String
    06. 
    07.     Public Property Text() As String
    08.         Get
    09.             Return text1
    10.         End Get
    11.         Set(ByVal value As String)
    12.             text1 = value
    13.         End Set
    14.     End Property
    15. 
    16. 
    17.     Public Property ID() As Integer
    18.         Get
    19.             Return id1
    20.         End Get
    21.         Set(ByVal value As Integer)
    22.             id1 = value
    23.         End Set
    24.     End Property
    25. 
    26.     Public Property ParentID() As Integer
    27.         Get
    28.             Return parentId1
    29.         End Get
    30.         Set(ByVal value As Integer)
    31.             parentId1 = value
    32.         End Set
    33.     End Property
    34. 
    35.     Public Property Report_ID() As String
    36.         Get
    37.             Return report_id1
    38.         End Get
    39.         Set(ByVal value As String)
    40.             report_id1 = value
    41.         End Set
    42.     End Property
    43. 
    44.     Public Sub New(ByVal id As Integer, ByVal parentId As Integer, ByVal text As String, Optional ByVal report_id1 As String = "99")
    45.         Me.id1 = id
    46.         Me.parentId1 = parentId
    47.         Me.text1 = text
    48.         Me.report_id1 = Report_ID
    49.         
    50.     End Sub
    51.      
    52.      
    53.     '--------- Constractor
    54.     Public Sub New(ByVal id As Integer, ByVal parentId As Integer, ByVal text As String, Optional ByVal report_id1 As String = "99")
    55.         Me.id1 = id
    56.         Me.parentId1 = parentId
    57.         Me.text1 = text
    58.         Me.report_id1 = Report_ID
    59.        
    60.     End Sub
    61. End Class
    62.  
    63. '=======
    64.  
    65.  
    66.    Private Sub BindToIEnumerable(ByVal treeView As RadTreeView)
    67.     Dim siteData As New List(Of SiteDataItem)()
    68. 
    69.     siteData.Add(New SiteDataItem(1, 0, "Location"))
    70.     siteData.Add(New SiteDataItem(2, 0, "Hobbies"))
    71.     siteData.Add(New SiteDataItem(3, 1, "func 1", "101"))
    72.     siteData.Add(New SiteDataItem(4, 1, "func 2", "102"))
    73.     siteData.Add(New SiteDataItem(5, 2, "func 4", "103"))
    74.     siteData.Add(New SiteDataItem(6, 2, " func 1" , "104"))
    75. 
    76. 
    77.     treeView.DataTextField = "Text"
    78.     treeView.DataFieldID = "ID"
    79.     treeView.DataFieldParentID = "ParentID"
    80.     treeView.DataValueField = "Report_ID"
    81.     treeView.DataSource = siteData
    82.     treeView.DataBind()
    83. 
    84.     
    85. 
    86. End Sub

    As you see, I insert a value,text,iD &parent_id into the RadTreeView,   [line 77-80]
    All is built well : the text,ID & Parent_id. But when I try to get the value field it shows me null:


    Protected Sub treeView_SideMenu_NodeClick(sender As Object, e As RadTreeNodeEventArgs) Handles treeView_SideMenu.NodeClick
     
     
           Session("funcID") = e.Node.Value  'Unfortunately return NULL
     
     
     
       End Sub

    p.s
    I Must use the "Value" Property and not "by text" ,because I've identical text menu





  2. Daniel
    Daniel avatar
    159 posts
    Member since:
    Feb 2014

    Posted 23 Mar 2014 in reply to Daniel Link to this post

    I just found my problem:
    I have a problem with the Constractor [line 53-58]
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Mar 2014 in reply to Daniel Link to this post

    Hi Daniel,

    Please have a look into the sample code snippet which works fine at my end.

    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" runat="server" OnNodeClick="RadTreeView1_NodeClick">
    </telerik:RadTreeView>

    VB:
    Friend Class SiteDataItem
        Private m_text As String
        Private m_id As Integer
        Private m_parentId As Integer
        Private m_valueId As String
        Public Property Text() As String
            Get
                Return m_text
            End Get
            Set
                m_text = value
            End Set
        End Property
        Public Property ID() As Integer
            Get
                Return m_id
            End Get
            Set
                m_id = value
            End Set
        End Property
        Public Property ParentID() As Integer
            Get
                Return m_parentId
            End Get
            Set
                m_parentId = value
            End Set
        End Property
        Public Property ValueID() As String
            Get
                Return m_valueId
            End Get
            Set
                m_valueId = value
            End Set
        End Property
        Public Sub New(id As Integer, parentId As Integer, text As String, Optional valueId As String = "")
            Me.m_id = id
            Me.m_parentId = parentId
            Me.m_text = text
            Me.m_valueId = valueId
        End Sub
    End Class
    Protected Sub Page_Load(sender As Object, e As EventArgs)
        If Not Page.IsPostBack Then
            BindToIEnumerable(RadTreeView1)
        End If
    End Sub
    Private Shared Sub BindToIEnumerable(treeView As RadTreeView)
        Dim siteData As New List(Of SiteDataItem)()
        siteData.Add(New SiteDataItem(1, 0, "Location"))
        siteData.Add(New SiteDataItem(2, 0, "Hobbies"))
        siteData.Add(New SiteDataItem(3, 1, "func 1", "101"))
        siteData.Add(New SiteDataItem(4, 1, "func 2", "102"))
        siteData.Add(New SiteDataItem(5, 2, "func 4", "103"))
        siteData.Add(New SiteDataItem(6, 2, " func 1", "104"))
     
        treeView.DataTextField = "Text"
        treeView.DataFieldID = "ID"
        treeView.DataFieldParentID = "ParentID"
        treeView.DataValueField = "ValueID"
        treeView.DataSource = siteData
        treeView.DataBind()
    End Sub
    Protected Sub RadTreeView1_NodeClick(sender As Object, e As RadTreeNodeEventArgs)
        Dim value As String = e.Node.Value
        Response.Write(value)
    End Sub

    Thanks,
    Princy.
Back to Top