Im trying to loop over a list of downloads selected from a multi node picker in a user control can anyone point me in the right direction of going about this.
foreach (Node childNode in currentNode.Children) { if (childNode.NodeTypeAlias == "downloads") { downloadsNode = childNode; break; } }
With the downloadsNode containg the MultiNodePicker property, the following will return the XML string stored by the MultiNodePicker: eg. "<MultiNodePicker><nodeId>1</nodeId><nodeId>2</nodeId></MultiNodePicker>"
if (pickerProperty != null) { pickerValue = pickerProperty.Value; }
To process this XML string and return a collection of Nodes:
List<Node> pickedNodes = new List<Node>(); Node node; int id;
using (XmlReader xmlReader = XmlReader.Create(new StringReader(pickerValue))) { xmlReader.Read(); if(xmlReader.Name == "MultiNodePicker") { // Position on first <nodeId> xmlReader.ReadStartElement();
while (!xmlReader.EOF) { if(xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "nodeId") { node = new Node(xmlReader.ReadElementContentAsInt()) if (node != null) { pickedNodes.Add(node); } } else { // Step the reader on xmlReader.Read(); } } } }
Here's an example using the uQuery helper library which allows Linq queries to navigate the node structure, handles the null checks and creates a Node collection from a Multi-Node Tree Picker Xml snippet:
Looping over downloads in a user control
Hi all,
Im trying to loop over a list of downloads selected from a multi node picker in a user control can anyone point me in the right direction of going about this.
I know in xslt to do it I simply use;
Thanks
John
Hi John,
I think you need a little more.
Try something like this:
<xsl:for-each select="$currentPage/downloads/MultiNodePicker/nodeId">
Hi Anders,
Maybe I didnt as that very well. I know how to do it in a xslt file no problem in my current scenraio im attempting to do this in a c# user control.
Thanks
John
Okay, then I'm not the guy to ask :)
//Anders
Hi John,
I'm guessing you're using the Multi-Node Tree Picker and saving your data as XML ?
Using the node factory API, from the current node you could loop though each Node in the Node.Children property to find the 'downloads' Node:
With the downloadsNode containg the MultiNodePicker property, the following will return the XML string stored by the MultiNodePicker:
eg. "<MultiNodePicker><nodeId>1</nodeId><nodeId>2</nodeId></MultiNodePicker>"
To process this XML string and return a collection of Nodes:
Here's an example using the uQuery helper library which allows Linq queries to navigate the node structure, handles the null checks and creates a Node collection from a Multi-Node Tree Picker Xml snippet:
HTH,
Hendy
is working on a reply...