views:

30

answers:

1

I am adding a new item to a list in SharePoint 2007. One of the columns is a lookup into another list. Here is the code:

li["LOOKUP"] = new SPFieldLookupValue(1,VALUE);

The entry in the list isn't correct and is always using the first value in the other list. When I look at the value of li["LOOKUP"] in the debugger all I get is "1".

VALUE is in the other list and it is the first column.

A: 

When adding items to a list only the id of the element from the list being looked up needs to be provided. It was always adding the first element because I always passed in "1". The following code looks up the value and then gets its id and passed this to the field:

SPListItemCollection lookup = LIST.GetItems(qry);
li["LOOKUP"] = lookup[0][SPBuiltInFieldId.ID].ToString();
Mike Polen

related questions