如何使用网格更新sharepoint查找列?

如何使用网格更新sharepoint查找列?,sharepoint,sharepoint-2013,sharepoint-online,Sharepoint,Sharepoint 2013,Sharepoint Online,我有一个员工列表,其中有两列(部门和经理),它们是查找列。我需要在新用户注册时更新这些查找列的代码。(尽管列表中的其他列正在更新) 代码如下: using (ClientContext clientContext = new ClientContext("https://sp13appstoredev.xyz.com/sites/DevApps/TrainingSite/")) { clientContext.Load(clientContext.Web, web =&g

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

代码如下:

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();