Add Attributes to Nodes?

4 posts, 0 answers
  1. Madhu Palakurthi
    Madhu Palakurthi avatar
    48 posts
    Member since:
    Nov 2009

    Posted 10 Dec 2012 Link to this post

    Hi,

    I am binding RadTreeView dynamically like this ..

    Dim siteData As New List(Of TreeViewCheckbox)()
              tvChkSearchResult.Attributes.Clear()
              If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
                  siteData.Add(New TreeViewCheckbox(1, 0, "Select All"))
     
                  Dim i As Integer = 0
                  Do While (i < dt.Rows.Count)
                      Dim row As DataRow = dt.Rows(i)
                      Dim srColumn As String = row(searchedColumn)
                      i = (i + 1)
                      siteData.Add(New TreeViewCheckbox(i + 1, 1, srColumn))
                      
     
                  Loop
              End If
     
              tvChkSearchResult.DataTextField = "Text"
              tvChkSearchResult.DataFieldID = "ID"
              tvChkSearchResult.DataFieldParentID = "ParentID"
              tvChkSearchResult.DataSource = siteData
              tvChkSearchResult.CausesValidation = False
              tvChkSearchResult.DataBind()

    Here TreeViewCheckbox is my class is defined like this ..
    Public Class TreeViewCheckbox
     
        Private _text As String
        Private _id As Integer
        Private _parentId As Integer
     
        Public Property Text() As String
            Get
                Return _text
            End Get
            Set(ByVal value As String)
                _text = value
            End Set
        End Property
     
     
        Public Property ID() As Integer
            Get
                Return _id
            End Get
            Set(ByVal value As Integer)
                _id = value
            End Set
        End Property
     
        Public Property ParentID() As Integer
            Get
                Return _parentId
            End Get
            Set(ByVal value As Integer)
                _parentId = value
            End Set
        End Property
     
        Public Sub New(ByVal id As Integer, ByVal parentId As Integer, ByVal text As String)
            _id = id
            _parentId = parentId
            _text = text
        End Sub
    End Class


     How can I add attributes to every node ? please help me on this..

    Thanks in advance..
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Dec 2012 Link to this post

    Hi,

    You can add attributes to every node in the NodeDataBound event of RadTreeView.

    C#:
    protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e)
        {
            e.Node.Attributes.Add("My Key", "My Value");
        }

    Please take a look into this documentation for more information.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Madhu Palakurthi
    Madhu Palakurthi avatar
    48 posts
    Member since:
    Nov 2009

    Posted 11 Dec 2012 Link to this post

    Hi,

    I have done treeview binding programmatic way from here..
    http://demos.telerik.com/aspnet-ajax/treeview/examples/programming/databinding/defaultvb.aspx

    there is no sample for adding attributes programmatic.

    Finally I loop all nodes after binding and add attribute values from data table.

    tvChkSearchResult.DataTextField = "Text"
              tvChkSearchResult.DataFieldID = "ID"
              tvChkSearchResult.DataFieldParentID = "ParentID"
              tvChkSearchResult.DataSource = siteData
              'tvChkSearchResult.CausesValidation = False
              tvChkSearchResult.DataBind()
     
              For Each node As RadTreeNode In tvChkSearchResult.GetAllNodes()
                  If dt IsNot Nothing And dt.Rows.Count > 0 Then
                      If node.Text <> "Select All" Then
                          For Each dr As DataRow In dt.Select("" + searchedColumn + "= '" + node.Text + "'")
                              node.Attributes.Add("ConsignmentNo", dr("ConsignmentNo").ToString())
                              node.Attributes.Add("CourierSlipDate", dr("CourierSlipDate").ToString())
                              node.Attributes.Add("DateOfCoverLetter", dr("DateOfCoverLetter").ToString())
                          Next
                      End If
                  End If
              Next


    Is there way to add attributes when adding values in to sitedata list?

    Here sitedata is the list and TreeViewCheckbox is custom class that defined id,parentid ..etc properties.
    Dim siteData As New List(Of TreeViewCheckbox)()
              tvChkSearchResult.Attributes.Clear()
              If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
                  siteData.Add(New TreeViewCheckbox(1, 0, "Select All"))
     
                  Dim i As Integer = 0
                  Do While (i < dt.Rows.Count)
                      Dim row As DataRow = dt.Rows(i)
                      Dim srColumn As String = row(searchedColumn)
                      i = (i + 1)
                      siteData.Add(New TreeViewCheckbox(i + 1, 1, srColumn))
                      
     
                  Loop
              End If

  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Dec 2012 Link to this post

    Hi,

    The NodeDataBound fires for every Node that is bound to data. You can add the attributes in the NodeDataBound event as follows.

    VB:
    Protected Sub RadTreeView1_NodeDataBound(sender As Object, e As RadTreeNodeEventArgs)
        e.Node.Attributes.Add("ConsignmentNo", dr("ConsignmentNo").ToString())
        e.Node.Attributes.Add("CourierSlipDate", dr("CourierSlipDate").ToString())
        e.Node.Attributes.Add("DateOfCoverLetter", dr("DateOfCoverLetter").ToString())
    End Sub

    Regards,
    Princy.
Back to Top