【问题标题】:How to update a sharepoint lookup column using a grid?如何使用网格更新共享点查找列?
【发布时间】:2017-08-09 14:29:40
【问题描述】:

我有一个员工列表,其中有 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();
    }

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

请帮助。谢谢:)

【问题讨论】:

    标签: sharepoint sharepoint-2013 sharepoint-online


    【解决方案1】:

    添加以下行有效:

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-26
        • 2022-01-11
        • 1970-01-01
        • 1970-01-01
        • 2011-12-26
        • 1970-01-01
        • 1970-01-01
        • 2010-09-26
        相关资源
        最近更新 更多