Let’s see how we can retrieve/Update SharePoint list
task predecessors programmatically.
Here is the sample code for retrieve/Update
SharePoint list task predecessors.
Retrieve Predecessors
SPListItem item = Selectedlist.GetItemById(taskID);SPFieldLookupValueCollection objLookupFieldValueCol = new SPFieldLookupValueCollection(item["Predecessors"].ToString());for (int i = 0; i < objLookupFieldValueCol.Count; i++){SPFieldLookupValue singlevalue = objLookupFieldValueCol[i];//use singlevalue to get other details [singlevalue.LookupId ,singlevalue.LookupValue]}
Update Predecessors
SPListItem itemToUpdate = Selectedlist.GetItemById(taskID);// dtSelectedPredecessors = selected Predecessors datatableSPFieldLookupValueCollection objLookupFieldValueCol = new SPFieldLookupValueCollection();for (int i = 0; i < dtSelectedPredecessors.Rows.Count; i++){SPFieldLookupValue objLookupFieldValue = new SPFieldLookupValue();objLookupFieldValue.LookupId = Convert.ToInt32(dtSelectedPredecessors.Rows[i]["itemID"].ToString());objLookupFieldValueCol.Add(objLookupFieldValue);}itemToUpdate [SPBuiltInFieldId.Predecessors] = objLookupFieldValueCol;itemToUpdate.Update();
This comment has been removed by the author.
ReplyDeleteRef1: http://social.msdn.microsoft.com/Forums/is/sharepointdevelopmentprevious/thread/f749432e-028d-44b6-bdcd-33e6b57ca9ab
ReplyDeleteRef2:http://www.sharepointkings.com/2009/04/spfieldlookupvalue-and.html