如何使用网格更新共享点查找列?



我有一个员工列表,其中有 2 列(部门和经理(,它们是查找列。我需要代码在新用户注册时更新这些查找列。(尽管列表中的其他列正在更新(

以下是代码:

using (ClientContext clientContext = new ClientContext("https://sp13appstoredev.xyz.com/sites/DevApps/TrainingSite/"))
{
clientContext.Load(clientContext.Web, web => web.Title);
List oList = clientContext.Web.Lists.GetByTitle("Employees");
clientContext.Load(oList);
ListItemCreationInformation itemInfo = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem myItem = oList.AddItem(itemInfo);
myItem["Title"] = txtFirstName.Text;
myItem["Last_x0020_Name"] = txtLastName.Text;
myItem["u5ib"] = txtAge.Text;
myItem["Address"] = txtAddress.Text;
//FieldLookupValue lookUpDepartment = new FieldLookupValue();
//myItem["Department"] = lookUpDepartment as FieldLookupValue;
//FieldLookupValue lookUpManager = new FieldLookupValue();
//myItem["Manager"] = lookUpManager as FieldLookupValue;
myItem["Gender"] = radioBtnGender.Text;
myItem["Salary"] = txtSalary.Text;
myItem.Update();
clientContext.ExecuteQuery();
}

我注释了查找列行以检查列表中的其他列是否正在更新。

请帮忙。谢谢:)

添加以下行有效:

myItem["Department"] = 1; 
myItem["Manager"] = 1; 

我还必须将父列表设置为ID(以前它只是标题(

这是一个更好的解决方案:

//Department column
FieldLookupValue deptItem = new FieldLookupValue();
deptItem.LookupId = Convert.ToInt32(DropDownListDepartment.SelectedValue);
myItem["Department"] = deptItem;
myItem.Update();
//Manager column
FieldLookupValue managerItem = new FieldLookupValue();
managerItem.LookupId = Convert.ToInt32(DropDownListManager.SelectedValue);
myItem["Manager"] = managerItem;
myItem.Update();

最新更新