2

I have created a visual WebPart contains a people Editor control to pick the Manager Name(infact only one name). The control is working fine but i would like to store the particular value to a variable using code during the button click . how can i achive this ? any help?

missReclusive
  • 105
  • 1
  • 4
  • 20

2 Answers2

6

Hope this code is helpful for you..

public void btnSave_Click(object sender, System.EventArgs e)
{
   ….
   //where userPicker is Id of People picker control
   PickerEntity pe = (PickerEntity)userPicker.Entities[0];  
   string username = pe.Description;
   …
}
SWeko
  • 30,434
  • 10
  • 71
  • 106
Rony SP
  • 2,618
  • 15
  • 16
5

I got the answer.Thanks for the idea. Below is the code which works fine for me.

    SPWeb mySite = SPContext.Current.Web;

    SPListItemCollection listItems = mySite.Lists["myList"].Items;

    SPListItem item = listItems.Add();

    string[] UsersSeperated = pplEditor.CommaSeparatedAccounts.Split(',');

    SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();

    foreach (string UserSeperated in UsersSeperated)

       {

    mySite.EnsureUser(UserSeperated);

    SPUser User = mySite.SiteUsers[UserSeperated];

    SPFieldUserValue UserName = new SPFieldUserValue(mySite, User.ID, User.LoginName);

    UserCollection.Add(UserName);

   }

item["people"] = UserCollection;

item.Update();
Jignesh Rajput
  • 3,538
  • 30
  • 50
missReclusive
  • 105
  • 1
  • 4
  • 20