Binding People Picker Value to SharePoint List Using C#

Binding People Picker value to SharePoint List using C#
 
HTML code:
  1. <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:
  1. public SPFieldUserValue GetSPUserValue(SPWeb objSPWeb, PeopleEditor pplEditor)  
  2. {  
  3.     try  
  4.     {  
  5.         SPFieldUserValue userValue = null;  
  6.         if (pplEditor.Entities.Count > 0)  
  7.         {  
  8.             PickerEntity pplAssigned = (PickerEntity) pplEditor.Entities[0];  
  9.             SPUser webUser = objSPWeb.EnsureUser(pplAssigned.Key);  
  10.             userValue = new SPFieldUserValue(objSPWeb, webUser.ID, webUser.Name);  
  11.         }  
  12.         return userValue;  
  13.     }  
  14.     catch (Exception ex)  
  15.     {  
  16.         // Log exception  
  17.     }  
  18. }  
Calling the function to bind the user value to list item:
  1. SPListItemCollection listItems = web.Lists["ListName"].Items;  
  2. SPListItem item = listItems.Add();  
  3. item["ListColumn"] = GetSPUserValue(web, myPPLControl);