Hi Sherry, the most simple way to do that is by doing something like this:
// get the node from the supplied nodeId
Node n = new Node(nodeId);
// loop over the nodefactories children
foreach (Node node in n.Children)
{
// output node name
return node.Name;
}
There are ways to pass in the node ID and I'm not sure that Dictionary Item is the best vehicle. It may be, but if you can describe in greater detail what you are trying to accomplish we may be able to suggest.
Depends on what you want to do with those nodes when you iterate them.
Complicated jobs are better suited to C#, but simple queries like "get" operations (name, media, etc.) is much easier to use Razor,(or Ruby or Python) or XSLT IMHO.
How do I loop trough the nodes using c#
Is it possible to loop through the nodes like the for-each using c#?
you have number of options: you can create a razor script,
create a usercontrol and use nodeFactory or uql or ucomponents with uQuery
I already have a user control. But how do I do it?
try ..
read nodes first.
i assume you have list of nodes like this nodes[];
than start to loop.
foreach(var v in nodes[])
{
response.write(v);
}
Sherry,
The answer depends a lot on the context.
Do you wish to loop through only published or both published and unpublished nodes?
Where do you want to loop from, the whole site? current page?
Rich
I will pass the node like this:
I need to loop throug the child nodes of the nodeID.
Hi Sherry, the most simple way to do that is by doing something like this:
There are ways to pass in the node ID and I'm not sure that Dictionary Item is the best vehicle. It may be, but if you can describe in greater detail what you are trying to accomplish we may be able to suggest.
Thanks,
Nik
What about if I use razor script? will it be much better in terms of flexibility?
Depends on what you want to do with those nodes when you iterate them.
Complicated jobs are better suited to C#, but simple queries like "get" operations (name, media, etc.) is much easier to use Razor,(or Ruby or Python) or XSLT IMHO.
is working on a reply...