Wednesday, August 11, 2010

Updating a SharePoint List Item with a LookUp Column

I got this error
"Invalid data has been used to update the list item. The field you are trying to update may be read only" when I was trying to Update a List with a LookUp column called "Group".
This column looked up values from another list. The solution was to update the ID of the lookup column and it worked .
Here is the code snippet for the above:
SPList lst = listWeb.Lists[listName];
//Get the items of the list
SPListItem item = lst.Items.GetItemById(ItemID);

//Set the item of the list to the corresponding Group Name from the "LookUp" list .Note Group1 is the Internal name of the column Group
item["Group1"] = intGroupID;
listWeb.AllowUnsafeUpdates = true;
//The argument false for SystemUpdate informs the SPObject Model not to increment versions
item.SystemUpdate(false);
listWeb.AllowUnsafeUpdates = false;

No comments: