将多个查找值插入/更新到 SPListItem

发布于 2024-08-24 06:28:48 字数 789 浏览 5 评论 0原文

我的 SharePoint 列表有一列允许多个查找值。我的 C# 控件(在 Web 部件内)允许用户从列表框中进行多项选择。我将这些值拆分为一个数组 - 每个数组成员都是需要在同一 SPListItem 列中更新的选定值。

我知道选择是从列表框中正确传递的 - 我只需要将这组值添加到 SPListItem 中的同一列。

我哪里错了?

SPFieldLookupValueCollection MyCollection = new SPFieldLookupValueCollection();
for (int i = 0; i < MyArrayOfSelections.Length; i++)
{
   if (MyLookupList["LookupColumn"].ToString() == MyArrayOfSelections[i].ToString())
   {
      MyID = int.Parse(MyLookupList[i]["ID"].ToString());
      SPFieldLookupValue thisSelection = new SPFieldLookupValue(MyID,MyArrayOfSelections[i].ToString());
      MySubCollection.Add(thisSelection);
      }
   }
   ListIWantToUpdate["ColumnWithMultipleLookupSelections"] = SubCollection;
   ListIWantToUpdate.Update();
   site.Update();
}

My SharePoint list has a column that allows multiple lookup values. My C# control (within a webpart) allows the user to make multiple selections from a list box. I split these values into an array - each array member being a selected value that needs to be updated in the same SPListItem column.

I know that the selections are being passed in properly from the list box - I just need to add this group of values to the same column in the SPListItem.

Where am I going wrong?

SPFieldLookupValueCollection MyCollection = new SPFieldLookupValueCollection();
for (int i = 0; i < MyArrayOfSelections.Length; i++)
{
   if (MyLookupList["LookupColumn"].ToString() == MyArrayOfSelections[i].ToString())
   {
      MyID = int.Parse(MyLookupList[i]["ID"].ToString());
      SPFieldLookupValue thisSelection = new SPFieldLookupValue(MyID,MyArrayOfSelections[i].ToString());
      MySubCollection.Add(thisSelection);
      }
   }
   ListIWantToUpdate["ColumnWithMultipleLookupSelections"] = SubCollection;
   ListIWantToUpdate.Update();
   site.Update();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法言说的痛 2024-08-31 06:28:48

代码示例的最后几行令人困惑(也许只是变量命名)。如果您只是更新数据,则永远不需要更新 SPList 对象(这需要特定列表的“管理列表”权限),也不需要更新 SPSite< /code> ojbect(要求您是站点管理员或所有者)。因此,普通用户无法成功运行此代码。

The last rows of the code example are confusing (maybe it's just variable naming). If you are just updating the data, you never need to update neither the SPList object (this requires "Manage lists" permission on the particular list, nor SPSite ojbect (requires you to be site administrator or owner). So, this code will not run succcessfuly for a regular user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文