Get and Set Value of People Picker/Editor in Visual Webpart

Requirement – How to set value of people picker editor from code behind in visual web part.

How to add People Picker Webpart on Webpart – Go to webpart’s user control and add below

<SharePoint:PeopleEditor ID=“myPeoplePicker” runat=“server” Width=“300” BorderStyle=“Solid” BorderColor=“Black” BorderWidth=“1” />

Reading Value from control

if(myPeoplePicker.ResolvedEntities.Count >0 )
{
PickerEntity objEntity = (PickerEntity) myPeoplePicker.ResolvedEntities[0];
SPUserInfo objInfo = new SPUserInfo();
objInfo.LoginName = objEntity.Key;
strAccountName = objInfo.LoginName; 
//objEntity.EntityData Gets or sets a data-mapping structure that is defined by the consumer of the PickerEntity class. This properties has all data related to user entity.
}

Setting Value to Control

myPeoplePicker.CommaSeparatedAccounts = “domain\username”;
myPeoplePicker.ValidateEntity()

Hope this helps…Happy Coding!!!

(Visited 36 times, 1 visits today)