Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sander van de Pas 62 posts 122 karma points
    Jun 05, 2012 @ 13:42
    Sander van de Pas
    0

    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:

    //The Listbox
    <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)
    {
        if (li.Selected)
            locations += "<nodeId>" + li.Value + "</nodeId>";
    }
    member.getProperty("memberLocation").Value = locations.Length > 0 ?
                    string.Format("<MultiNodePicker>{0}</MultiNodePicker>", locations)
                    : "";
    
  • Lee Kelleher 3876 posts 14590 karma points MVP 9x admin c-trib
    Jun 05, 2012 @ 23:14
    Lee Kelleher
    0

    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.

  • Sander van de Pas 62 posts 122 karma points
    Jun 06, 2012 @ 09:39
    Sander van de Pas
    0

    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

    //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; } }
  • Lee Kelleher 3876 posts 14590 karma points MVP 9x admin c-trib
    Jun 06, 2012 @ 11:29
    Lee Kelleher
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft