This is a migrated thread and some comments may be shown as answers.

Add Attributes to Nodes?

3 Answers 297 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Madhu Palakurthi
Top achievements
Rank 1
Madhu Palakurthi asked on 10 Dec 2012, 12:44 PM
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..

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Dec 2012, 09:53 AM
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.
0
Madhu Palakurthi
Top achievements
Rank 1
answered on 11 Dec 2012, 10:15 AM
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

0
Princy
Top achievements
Rank 2
answered on 12 Dec 2012, 04:34 AM
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.
Tags
TreeView
Asked by
Madhu Palakurthi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Madhu Palakurthi
Top achievements
Rank 1
Share this question
or