Here is my situation. I have a tree that uses load on demand. The first level is Offices and the second level are Contacts in corresponding offices.
Now, the data source for the offices also returns the number of contacts in the office, which is helpful for this load on demand scenario (the user now knows if the office has nodes in it). However, to display the number in a different color beside the office title, I need to use a template of the Office Nodes. But I want the Contact Nodes below to be regular RadTreeNodes. Now I got it working one way programmatically, but I feel using template on the ASPX side would faster.
Here is my attempt at the ASPX side, which is completely broken and completely wrong, but I'm using it to give you a sense of where I am going.
Also, I am grabbing the offices by clicking on a Company Node on another tree, but using per-node template, a "blank" tree node appears in the Office tree on page load (before selecting any company).
The point here is speed. I want to use the fastest, most optimized method to do this.
Now, the data source for the offices also returns the number of contacts in the office, which is helpful for this load on demand scenario (the user now knows if the office has nodes in it). However, to display the number in a different color beside the office title, I need to use a template of the Office Nodes. But I want the Contact Nodes below to be regular RadTreeNodes. Now I got it working one way programmatically, but I feel using template on the ASPX side would faster.
Here is my attempt at the ASPX side, which is completely broken and completely wrong, but I'm using it to give you a sense of where I am going.
<
telerik:RadTreeView
ID
=
"_tvOffice"
AutoPostBack
=
"true"
Width
=
"100%"
Skin
=
"Office2007"
EnableDragAndDropBetweenNodes
=
"true"
EnableDragAndDrop
=
"True"
runat
=
"server"
DataFieldID
=
"ID"
ContextMenuItemClick
=
"_tvOffice_ContextMenuItemClick"
OnNodeExpand
=
"_tvOffice_NodeExpand"
>
<
NodeTemplate
>
<
telerik:RadTreeNode
runat
=
"server"
>
</
telerik:RadTreeNode
>
</
NodeTemplate
>
<
Nodes
>
<
telerik:RadTreeNode
EnableContextMenu
=
"false"
CssClass
=
"spIcon spFldr_C"
AllowDrag
=
"false"
AllowDrop
=
"true"
ExpandMode
=
"ServerSideCallBack"
runat
=
"server"
>
<
NodeTemplate
>
<
asp:Label
ID
=
"_lblTitle"
runat
=
"server"
Text='<%# DataBinder.Eval(Container, "DataItem.officeTitle")%>'></
asp:Label
>
<
asp:Label
ID
=
"_lblCount"
runat
=
"server"
Text='<%# DataBinder.Eval(Container, "DataItem.ContactCount", "({0})")%>'
CssClass="lblProjectNum"></
asp:Label
>
</
NodeTemplate
>
</
telerik:RadTreeNode
>
</
Nodes
>
<
DataBindings
>
<
telerik:RadTreeNodeBinding
Depth
=
"0"
EnableContextMenu
=
"false"
CssClass
=
"spIcon spFldr_C"
AllowDrag
=
"false"
AllowDrop
=
"true"
ExpandMode
=
"ServerSideCallBack"
TextField
=
"officeTitle"
ValueField
=
"ID"
CategoryField
=
"Category"
/>
</
DataBindings
>
</
telerik:RadTreeView
>
private void RebindOfficeTree(int? companyId)
{
if (companyId == null) return;
var db = new DBStoredProc();
var officeList = db.Offices_OnDemand(companyId);
_tvOffice.DataSource = officeList;
_tvOffice.DataBind();
}
private static void PopulateContactsByOffice(RadTreeNodeEventArgs e)
{
if (e == null || e.Node.Value == null) return;
var db = new DataContext();
var officeId = int.Parse(e.Node.Value);
var contactList = Contacts.LoadByOfficeId(db, officeId);
foreach (var contact in contactList)
{
var node = new RadTreeNode
{
Text = contact.FullName,
Value = contact.Id.ToString(),
CssClass = "spIcon spContact",
Category = "Contact",
AllowDrag = true,
AllowDrop = false
};
e.Node.Nodes.Add(node);
}
e.Node.Expanded = true;
}
Also, I am grabbing the offices by clicking on a Company Node on another tree, but using per-node template, a "blank" tree node appears in the Office tree on page load (before selecting any company).
The point here is speed. I want to use the fastest, most optimized method to do this.