1

I have a SharePoint List who has the column of type Person or Group.

In my webpart solution I am trying to use Caml Query to get the Data of the List based on Department column. Each Department is assigned with Multiple Number of Persons.

I want to fill a Dropdown to Select Person from Dropdown and the Dropdown must be filled with the data returned based on Department

I've gone through this but couldn't find any solution of using my own list in SharePoint People Picker Control

Following is the Image of my List:

enter image description here

Please Help, How can I Fill People Picker Control using this List in C# Solution

Thanks

1
  • Did you try the code snippet below ?
    – Jerry
    Commented Jun 26, 2019 at 2:51

1 Answer 1

0

Sample code snippet for your reference:

.ascx:

<SharePoint:ClientPeoplePicker runat="server" ID="PeoplePickerControlName" Required="true" ValidationEnabled="true" InitialHelpText="text" VisibleSuggestions="3" Rows="1" AllowMultipleEntities="true" CssClass="ms-long ms-spellcheck-true" />

ascx.cs:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections.Generic;

namespace FillUser.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (SPSite site=new SPSite("http://sp/sites/jerry"))
            {
                SPWeb web = site.OpenWeb();
                SPList list = web.Lists["JerryList4"];
                SPListItem item = list.GetItemById(6);
                SPFieldUserValueCollection reviewers = (SPFieldUserValueCollection)item["Reviewers"];
                List<PickerEntity> reviewersEntity = new List<PickerEntity>();
                foreach (SPFieldUserValue spuserval in reviewers)
                {

                    SPUser userToassign = spuserval.User;
                    PickerEntity entity = new PickerEntity();
                    PeopleEditor pe = new PeopleEditor();
                    entity.EntityData["AccountName"] = spuserval.User.LoginName;
                    entity.EntityData["SPUserID"] = spuserval.User.ID;
                    entity.EntityData["Email"] = spuserval.User.Email;
                    entity.Key = spuserval.User.LoginName;
                    entity.Description = spuserval.User.LoginName;
                    entity.DisplayText = spuserval.User.Name;
                    entity = pe.ValidateEntity(entity);
                    entity.IsResolved = true;
                    reviewersEntity.Add(entity);
                }
                PeoplePickerControlName.AddEntities(reviewersEntity);
                }

        }
    }
}

enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.