Reputation: 105
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?
Upvotes: 2
Views: 20342
Reputation: 2628
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;
…
}
Upvotes: 6
Reputation: 105
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();
Upvotes: 5