All Products
Demos
Pricing
Services
Blogs
Docs & Support
Search
Shopping cart
Login
Contact Us
Get A Free Trial
close mobile menu
Telerik Forums
/
UI for ASP.NET AJAX Forum
/
TreeView
/
Adding server-side custom properties to a treeview
Cancel
Telerik UI for ASP.NET AJAX
Resources
Buy
Try
Feed for this thread
3 posts, 0 answers
Bob Jones
8 posts
Member since:
Aug 2009
Posted 03 Nov 2009
Link to this post
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
Princy
17421 posts
Member since:
Mar 2007
Posted 03 Nov 2009
Link to this post
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.
Bob Jones
8 posts
Member since:
Aug 2009
Posted 03 Nov 2009
Link to this post
Thanks for the quick response. It works just fine.
Bob Jones
Back to Top
Close