Binding People Picker value to SharePoint List using C#
HTML code:
<SharePoint:PeopleEditor ID="pplEditor" runat="server" Rows="1" PlaceButtonsUnderEntityEditor="false" Width="250px" SelectionSet="User" />Function to get user value from people editor to bind to list column:
public SPFieldUserValue GetSPUserValue(SPWeb objSPWeb, PeopleEditor pplEditor)
{
try
{
SPFieldUserValue userValue = null;
if (pplEditor.Entities.Count > 0)
{
PickerEntity pplAssigned = (PickerEntity) pplEditor.Entities[0];
SPUser webUser = objSPWeb.EnsureUser(pplAssigned.Key);
userValue = new SPFieldUserValue(objSPWeb, webUser.ID, webUser.Name);
}
return userValue;
}
catch (Exception ex)
{
// Log exception
}
}Calling the function to bind the user value to list item:
SPListItemCollection listItems = web.Lists["ListName"].Items;
SPListItem item = listItems.Add();
item["ListColumn"] = GetSPUserValue(web, myPPLControl);