How to get and set the MNTP member property for a member
I have an intranet where I can change my member details. One property of a member is a MNTP.
I have a ListBox with all the selectable options in that MNTP, but now I want to get the selected nodes also selected in that listbox. And when I changed something and save it it must update that member property.
For the MNTP, are you using CSV or XML data? (From your code snippet, I'm guessing it's XML).
It looks like you are on the right track with saving the data from the ListBox back to MNTP, (e.g. constructing the XML string). The only part I see missing is getting the value from MNTP and selecting the ListBox items. Which you'd need to load up the MNTP's XML string into an XmlDocument (or XDocument) and loop through each nodeId.
Getting the value is the thing I didn't know how to do. After a while I got it working like the code below, but I think/hope there's a faster way to do this. Maybe you could give me the XDocument example for this instead of creating a list of integers and loop through all the items and see which need to be selected.
Thanks in advance!
Grtz Sander
//get the selected nodes and put the id of them in a list var selectedLocations = new DynamicXml(member.getProperty("memberLocation").Value.ToString());
var lstLocationNodeIds = new List<int>();
foreach (dynamic l in selectedLocations)
{
//Get the node base on the MNTP id and show the required data.
dynamic node = new DynamicNode(l.InnerText);
lstLocationNodeIds.Add(node.Id);
}
//loop through all the location nodes and check which one should be selected var locationNodes = topNode.Descendants(x => x.NodeTypeAlias == "Intranet-Location" || x.NodeTypeAlias == "Intranet-Agency").Items;
foreach (dynamic l in locationNodes)
{
ListItem li = new ListItem(l.GetPropertyValue("pageTitle"), l.Id.ToString());
lbLocation.Items.Add(li);
if (lstLocationNodeIds.Contains(l.Id))
{
li.Selected = true;
}
}
Your code snippet is the same approach that I would take too. Although I probably wouldn't create the 'DynamicNode', as you already have the nodeId value in the 'l.InterText'.
How to get and set the MNTP member property for a member
I have an intranet where I can change my member details. One property of a member is a MNTP.
I have a ListBox with all the selectable options in that MNTP, but now I want to get the selected nodes also selected in that listbox. And when I changed something and save it it must update that member property.
Could anyone help me?
Thanx!
This is what I have so far:
//Add the listbox items var locationNodes = topNode.Descendants(x => x.NodeTypeAlias == "Intranet-Location" || x.NodeTypeAlias == "Intranet-Agency").Items; foreach (var l in locationNodes) { lbLocation.Items.Add(new ListItem(l.GetPropertyValue("pageTitle"), l.Id.ToString())); }
Hi Sander,
For the MNTP, are you using CSV or XML data? (From your code snippet, I'm guessing it's XML).
It looks like you are on the right track with saving the data from the ListBox back to MNTP, (e.g. constructing the XML string). The only part I see missing is getting the value from MNTP and selecting the ListBox items. Which you'd need to load up the MNTP's XML string into an XmlDocument (or XDocument) and loop through each nodeId.
Let us know how you get on.
Cheers, Lee.
Hi Lee,
I'm using XML indeed ;-)
Getting the value is the thing I didn't know how to do. After a while I got it working like the code below, but I think/hope there's a faster way to do this.
Maybe you could give me the XDocument example for this instead of creating a list of integers and loop through all the items and see which need to be selected.
Thanks in advance!
Grtz Sander
Hi Sander,
Your code snippet is the same approach that I would take too. Although I probably wouldn't create the 'DynamicNode', as you already have the nodeId value in the 'l.InterText'.
Cheers, Lee.
is working on a reply...