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

Adding server-side custom properties to a treeview

2 Answers 106 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bob Jones
Top achievements
Rank 1
Bob Jones asked on 03 Nov 2009, 06:36 AM
I represent a directory structure with folders and documents that reside with a database;. The treeview is bound to a DataTable. I want to include additional properties that I can use in the On Node Data Bound event. With a GridView, I can add hidden fields to the Grid. I want to do the equivalent on the Treeview and include information such as the file type, its' creator, etc as additional non-visible fields within the TreeView when I bind it to the DataTable. All of the fields I want are columns in the table. I can't find any examples of how to do this. Help appreciated.

Thanks

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Nov 2009, 07:13 AM
Hi Bob Jones,

You can use Custom Attributes to include additional properties for each node than text and value field.

Checkout the example which shows how to add custom attributes in NodeDataBound event.
aspx:
<telerik:RadTreeView ID="RadTreeView1" runat="server" DataFieldID="CategoryID" DataSourceID="SqlDataSource1"  
    DataTextField="CategoryID" OnNodeDataBound="RadTreeView1_NodeDataBound" OnNodeClick="RadTreeView1_NodeClick">  
</telerik:RadTreeView>  

cs:
protected void RadTreeView1_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 RadTreeView1_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);    
}  

Hope this helps,
Princy.
0
Bob Jones
Top achievements
Rank 1
answered on 03 Nov 2009, 06:01 PM
Thanks for the quick response. It works just fine.

Bob Jones
Tags
TreeView
Asked by
Bob Jones
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bob Jones
Top achievements
Rank 1
Share this question
or