4 Answers, 1 is accepted
0
Hello Fahmi,
You can bind a TreeView instance (server-side) with a list of TreeNodeData type (see Binding to Array, ArrayList and Generic List: http://www.telerik.com/help/aspnet-ajax/treeview-data-binding-array.html) and then get all the nodes created in the TreeView - treeView.GetAllNodes().
Regards,
Nikolay Tsenkov
the Telerik team
You can bind a TreeView instance (server-side) with a list of TreeNodeData type (see Binding to Array, ArrayList and Generic List: http://www.telerik.com/help/aspnet-ajax/treeview-data-binding-array.html) and then get all the nodes created in the TreeView - treeView.GetAllNodes().
Regards,
Nikolay Tsenkov
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Joel Kraft
Top achievements
Rank 2
answered on 04 Jan 2012, 06:33 PM
This isn't a really great solution since you can only possibly get Text, NavigateUrl and Value bound to the nodes, and RadTreeNodeData contains a lot more information.
There really should be a constructor, or a cast, or a ToNode() method to create a node from the Data. This would allow the data returned from a webservice or page method to be easily reused on the server side.
There really should be a constructor, or a cast, or a ToNode() method to create a node from the Data. This would allow the data returned from a webservice or page method to be easily reused on the server side.
0
Hello Joel,
Plamen Zdravkov
the Telerik team
Thank you for the suggestion. We will consider implementing it in the future.
Would you please explain the exact scenario where you need this functionality so we can inspect it and compare it with other possible workarounds.
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Joel Kraft
Top achievements
Rank 2
answered on 31 Jan 2012, 03:07 PM
The scenario we ran into was this:
Here's the workaround we ended up using:
- Root-level tree nodes represent periods of time.
- Only the node for the current period should be expanded at load.
- Other nodes' children are lazy-loaded upon expanding (using page method call).
- We wanted to use the same method to load child nodes whether it was happening during page load or as part of a node expanding.
Here's the workaround we ended up using:
private
void
Page_Load()
{
// snip SQL code to load periods
using
(SqlDataReader r = sqlh.ExecuteReader())
{
while
(r.Read())
{
// create node for the period
RadTreeNode n =
new
RadTreeNode();
// if this is the current period
if
(r.GetString(5)[0] ==
'Y'
)
{
// load children
foreach
(RadTreeNodeData data
in
GetTermNodes(residentId, termId))
{
n.Nodes.Add(NodeFromData(data));
}
n.Expanded =
true
;
n.ExpandMode = 0;
}
}
}
[WebMethod]
public
static
RadTreeNodeData[] LoadNodes(RadTreeNodeData node,
object
context)
{
string
[] chunks = node.Value.Split(
'-'
);
if
(chunks.Length < 2)
return
CreateNodeData(
"Could not get resident and term ID."
);
int
residentId;
if
(!chunks[0].TryParseInt32(
out
residentId))
return
CreateNodeData(
"Invalid resident ID."
);
short
termId;
if
(!chunks[1].TryParseInt16(
out
termId))
return
CreateNodeData(
"Invalid term ID."
);
return
GetTermNodes(residentId, termId).ToArray();
}
private
static
List<RadTreeNodeData> GetTermNodes(
int
residentId,
short
termId)
{
List<RadTreeNodeData> nodes =
new
List<RadTreeNodeData>();
// snip code to generate child nodes
return
nodes;
}
private
static
RadTreeNode NodeFromData(RadTreeNodeData data)
{
RadTreeNode node =
new
RadTreeNode(data.Text, data.Value, data.NavigateUrl);
node.ContextMenuID = data.ContextMenuID;
node.ExpandMode = data.ExpandMode;
node.ImageUrl = data.ImageUrl;
return
node;
}
<
TELERIK:RadTreeView
ID
=
"tvTerms"
runat
=
"server"
>
<
WebServiceSettings
Path
=
"Default.aspx"
Method
=
"LoadNodes"
/>
</
TELERIK:RadTreeView
>