如果一个列表中有一个字段类型为用户或用户组,并且设置为用户,允许多值的话,那么用代码进行更新的时候就必须将这个字段的值赋成SPFieldUserValueCollection类型,以下代码即为从PeopleEditor控件中取出多个用户并返回一个SPFieldUserValueCollection类型的值:

 /// <summary>
/// 从人员选取器中获取多用户并返回SPFieldUserValueCollection类型
/// </summary>
/// <param name="pe">人员选取器</param>
/// <returns></returns> ToString:user1ID;#user1Name;#user2ID;#user2Name
public SPFieldUserValueCollection GetUsersValue(PeopleEditor pe)
{
SPFieldUserValueCollection result = new SPFieldUserValueCollection();
using (SPSite mySite = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb myWeb = mySite.RootWeb)
{
if (pe.CommaSeparatedAccounts != "")
{
foreach (string item in pe.CommaSeparatedAccounts.Split(','))
{
SPUser u = myWeb.EnsureUser(item);
SPFieldUserValue uservalue = new SPFieldUserValue(myWeb, u.ID, u.Name);
result.Add(uservalue);
}
}
}
}
return result;
}

更新的时候直接将item["user"]=GetUsersValue(pe);然后Update一下即可。

另外如果需要通过代码将多用户赋值给PeopleEditor控件,只需要设置PeopleEditor控件的CommaSeparatedAccounts属性为User1Name,User2Name这样即可,即为每个用户的DisplayName,然后之间用“,”隔开就可以了,代码如下:

pe.CommaSeparatedAccounts="User1Name,User2Name";

从PeopleEditor控件中取出多用户并更新到列表的更多相关文章

  1. 实现TableLayout布局下循环取出TableRow控件中的文字内容到list集合

    布局方式为TableLayout,利于实现表单样式展现. <!-- 详情内容区域 --> <ScrollView android:layout_above="@id/id_ ...

  2. winform窗体(六)——DataGridView控件及通过此控件中实现增删改查

    DataGridView:显示数据表,通过此控件中可以实现连接数据库,实现数据的增删改查 一.后台数据绑定:    List<xxx> list = new List<xxx> ...

  3. Winform(DataGridView)控件及通过此控件中实现增删改查

    DataGridView:显示数据表,通过此控件中可以实现连接数据库,实现数据的增删改查 一.后台数据绑定:    List<xxx> list = new List<xxx> ...

  4. WPF Image控件中的ImageSource与Bitmap的互相转换

    原文:WPF Image控件中的ImageSource与Bitmap的互相转换  1.从bitmap转换成ImageSource [DllImport("gdi32.dll", ...

  5. 在MonthCalendar控件中选中日期

    Calendar.MONTH Calendar now=Calendar.getInstance();System.out.print(now.get(Calendar.MONTH));得到的月份少1 ...

  6. .net dataGridView当鼠标经过时当前行背景色变色;然后【给GridView增加单击行事件,并获取单击行的数据填充到页面中的控件中】

    1.首先在前台dataGridview属性中增加onRowDataBound属性事件 2.然后在后台Observing_RowDataBound事件中增加代码 protected void Obser ...

  7. 服务器控件中使用<%#...>, JS和html控件中使用<%=...>

    //在服务器控件的属性中,需要用<%#...>来绑定其他控件的ID, 并且要在页面初始方法中,执行Page.DataBind(); <asp:ImageButton ID=" ...

  8. 在DataGridView控件中加入ComboBox下拉列表框的实现

    在DataGridView控件中加入ComboBox下拉列表框的实现 转自:http://www.cnblogs.com/luqingfei/archive/2007/03/28/691372.htm ...

  9. 关于使用MVVM模式在WPF的DataGrid控件中实现ComboBox编辑列

    最近在做一个组态软件的项目,有一个需求需要在建立IO设备变量的时候选择变量的类型等. 建立IO变量的界面是一个DataGrid实现的,可以一行一行的新建变量,如下如所示: 这里需要使用带有ComboB ...

随机推荐

  1. 11.Find All Numbers Disappeared in an Array(找出数组中缺失的数)

    Level:   Easy 题目描述: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements ...

  2. Step by Step: 基于MFC下的COM组件开发-Helloworld

    http://blog.csdn.net/sybifei/article/details/45008745 [这篇文章有问题, 仅供参考] http://blog.csdn.net/define_us ...

  3. 电路中IC器件电压符号的解释

    在电子芯片.运算处理器等集成电路行业中,存在多种电压.常用的的有:VDDQ->The supply voltage to output buffers of a memory chip 存储芯片 ...

  4. [ZJOI2018]历史(LCT)

    这篇还发了洛谷题解 [Luogu4338] [BZOJ5212] 题解 题意 给出一棵树,给定每一个点的 \(access\) 次数,计算轻重链切换次数的最大值,带修改. 先考虑不带修改怎么做 假设 ...

  5. Codeforce-A-Two distinct points(暴力)

    output standard output You are given two segments [l1;r1][l1;r1] and [l2;r2][l2;r2] on the xx-axis. ...

  6. jQuery中animate()方法以及$('body').animate({"scrollTop":top})不被Firefox支持问题的解决

    $("body").animate({"scrollTop":top}): 只被chrome支持,而不被Firefox支持 $("html" ...

  7. http文件上传/下载

    package unit; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputSt ...

  8. 移动性能测试 | 持续集成中的 Android 稳定性测试

    前言 谈到Android稳定测试,大多数会联想到使用monkey工具来做测试.google官方提供了monkey工具,可以很快速点击被应用,之前我有一篇帖子提到了monkey工具的使用,详见: htt ...

  9. vue2.0组件的生命周期

    beforeCreate(){ console.log(new Date().getTime()) let data = this.text; console.log('组件创立之前') consol ...

  10. oracle数据库代码块

    --申明变量.游标 declare a ):'; --逻辑 begin INSERT into TEMP_DSF.TEST VALUES (a); end; tips:mysql不支持匿名块.仅在存储 ...