Copied to clipboard

Flag this post as spam?

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


  • Martin Bentzen 83 posts 145 karma points
    Jul 19, 2009 @ 14:07
    Martin Bentzen
    0

    MemberGroup control

    Is the membergroup control (used on properties on member tabs) or similar available in a way that can be used in a custom usercontrol?

    I cant find it as datatype/rendercontrol nor in umbraco.editorcontrol namespace

    I work on a memberprofile usercontrol, where it should be possible to add/remove members from membergroups

    Thanx in advantage!

    Martin

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 19, 2009 @ 14:55
    Sebastiaan Janssen
    1

    I haven't seen anything out there, but it should not be hard to program this using member.AddGroup(int ID) and doing a umbraco.cms.businesslogic.member.MemberGroup.GetAll

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Jul 19, 2009 @ 14:55
    Peter Gregory
    2

    Hi martin

    Im not sure if there is a user control to do that but its pretty easy to build your own.   There is plenty of code around to build the two listboxes and the code to move items between  here is a link that may help with the interface.

    In terms of what you need to do with your codebind for adding a member to a selected group you would do something like this to loop through the listbox containing the selected groups and add them.

    Member m = Member.GetMemberFromEmail(Email); //or however you want to get your member.
    foreach(ListItem li in SelectedGroups.Items){
    m.AddGroup(MemberGroup.GetByName(li.Text).Id); //where the text property contains the name of the group
    }

    Member and MemberGroup is contained in umbraco.cms.businesslogic.member

    Hope that helps

  • Martin Bentzen 83 posts 145 karma points
    Jul 19, 2009 @ 15:03
    Martin Bentzen
    0

    Peter,

    Thanx for your reply. I'm familar with the techniques and API you mentioned, but I don't want to invent the wheel again. But if its not part of core or there is a package that fits, then I have to make one myself.

    Martin

     

  • Martin Bentzen 83 posts 145 karma points
    Jul 19, 2009 @ 20:46
    Martin Bentzen
    2

    Just digged into the editMember.aspx.cs code at core, and discovered how it was done there.

    The umbraco.controls.DualSelectBox is easy to use when such a control needed. Then I just "borrowed" the portion of code i needed

    controls.DualSelectbox _memberGroups = new controls.DualSelectbox();
    _memberGroups.ID = "Membergroups";
    _memberGroups.Width = 175;
    string selectedMembers = "";
    foreach(string role in Roles.GetAllRoles())
    {
    // if a role starts with __umbracoRole we won't show it as it's an internal role used for public access
    if (!role.StartsWith("__umbracoRole"))
    {
    ListItem li = new ListItem(role);
    if (!IsPostBack)
    {

    if (Roles.IsUserInRole(m_Member.UserName, role))
    selectedMembers += role + ",";
    }
    _memberGroups.Items.Add(li);
    }
    }
    _memberGroups.Value = selectedMembers;
  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 19, 2009 @ 22:14
    Sebastiaan Janssen
    0

    Thanks for posting the solution, very handy to have an easy reference for future use.

  • Hemant 9 posts 23 karma points
    Jul 20, 2009 @ 08:27
    Hemant
    0

    Thanks for sharing the solution.

Please Sign in or register to post replies

Write your reply to:

Draft