2017-08-07 26 views
1

我有一個員工列表,其中有2列(部門和經理),這是查找列。當新用戶註冊時,我需要代碼來更新這些查找列。 (雖然其它列被在列表更新)如何使用網格更新Sharepoint查找列?

以下是代碼:

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

我評論查找列線,以檢查是否在列表中被更新的另一列。

請幫忙。謝謝:)

回答

0

這是一個更好的解決方案:

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

添加以下行的工作:

myItem["Department"] = 1; 

myItem["Manager"] = 1; 

我也不得不設置父目錄的ID(以前它是唯一標題)

相關問題