Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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?
This is what I have so far:
<asp:ListBox ID="lbLocation" CssClass="multiple" SelectionMode="Multiple" runat="server" />
//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()));
//Get the selected locations
var locations = member.getProperty("memberLocation").Value.ToString();
//Save the locations
foreach (ListItem li in lbLocation.Items)
locations += "<nodeId>" + li.Value + "</nodeId>";
member.getProperty("memberLocation").Value = locations.Length > 0 ?
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.
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!
//get the selected nodes and put the id of them in a listvar 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);
//loop through all the location nodes and check which one should be selectedvar 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());
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'.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted