How to add value to search field in sharepoint?

Hi, I have two lists in sharepoint 2007. I have a search column in a list that displays another field. I want to use the sharepoint object model to add an item to the second list. How to set the value of the search field. (The value is already in another list.)?

SPListItem Employee = web.Lists["Employee"].Items.Add();
Employee["Name"] = account.Name;
Employee["Department"] = <lookup value must come here>
Employee.Update();                 
+5
source share
1 answer

The search fields will contain a combination of the row identifier and the value of the displayed column, divided :#, in your case, which may be 1:#HumanResourcesor 12:#Engineering.

, , . , SharePoint SPFieldLookupValue, :

var department = web.Lists["Department"].GetItemById(1);
var employee = web.Lists["Employee"].Items.Add();
employee["Name"] = account.Name;
employee["Department"] = new SPFieldLookupValue(department.ID, department.Title);
employee.Update(); 
+3

All Articles