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

Rad tree view :Binding custom attributes

1 Answer 210 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
piyush
Top achievements
Rank 1
piyush asked on 10 Jul 2009, 02:08 AM
I have following columns in my datasource which is a Generic list

Element ID
ParentElementID
Element Name
Sequence
Layer

I need to create and bind  custom attributes like Layer,Sequence,etc from the datasource so that I can manipulate them at Nodedatabound event .
Also for several childs of parent node
I need to order the sequence of nodes on the basis of Sequence .


1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 10 Jul 2009, 06:10 AM
Hi Piyush,

Checkout the following example which shows how to add custom attributes in NodeDataBound event.

ASPX:
 
<telerik:RadTreeView ID="RadTreeView2" runat="server" DataFieldID="CategoryID" DataSourceID="SqlDataSource1" 
    DataTextField="CategoryID" OnNodeDataBound="RadTreeView2_NodeDataBound" OnNodeClick="RadTreeView2_NodeClick"
</telerik:RadTreeView> 

C#:
 
protected void RadTreeView2_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e) 
    DataRowView dataSourceRow = (DataRowView)e.Node.DataItem; 
    //set custom attributes from the datasource:   
    e.Node.Attributes["CategoryName"] = dataSourceRow["CategoryName"].ToString();   
protected void RadTreeView2_NodeClick(object sender, RadTreeNodeEventArgs e) 
    String Name = e.Node.Text.ToString(); 
    String CategoryName = RadTreeView2.SelectedNode.Attributes["CategoryName"]; 
    Response.Write("You have selected " + Name + " with Name " + CategoryName);   

-Shinu.
Tags
TreeView
Asked by
piyush
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or