Today I was working on my custom web part. One of my questions was : after pressing submit button how to update a people and group field in the destination list.
I tested many ways and they gives me this error :
Invalid data has been used to update the list item. The field you are trying to update may be read only.
after searching and googling for some hours I found it in my way , here it is :
SPListItemCollection itemCollection; SPListItem item; PeopleEditor people; PickerEntity picker; SPUserInfo userInf; SPUser user; itemCollection = web.Lists["ListName"].Items; item = itemCollection.Add(); // I arranged my controls in a table // here is my one of people editor controls // So after pressing submit, the account of this control should set // new Item "Assigned To" field in the related list. people = (PeopleEditor)Tbl.Rows[0].Cells[0].Controls[0]; picker = (PickerEntity)people.ResolvedEntities[0]; userInf = new SPUserInfo(); user = web.EnsureUser(picker.Key); item["Assigned To"] = user; item.Update();
with this kind of coding my list start updating correctly
! hope this help you …
Also here is some related links that helped me :
- http://mysharepointblog.com/post/2007/07/How-to-use-the-PeoplePicker-in-SharePoint.aspx
- http://suguk.org/forums/post/13950.aspx
- http://blog.qumsieh.ca/2008/07/21/how-to-use-the-people-editor-control-loading-data-to-a-column-of-type-person-or-group/