首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

急求:新增数据时怎么将用户或用户组类型的字段添加到列表中

2012-03-20 
急求:新增数据时如何将用户或用户组类型的字段添加到列表中我的WebPart添加数据代码如下:SPSite site ne

急求:新增数据时如何将用户或用户组类型的字段添加到列表中
我的WebPart添加数据代码如下: 
SPSite site = new SPSite(@"http://lh-vmpc/personal/test/workflow");
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["WorkFlow"];
SPListItem item = list.Items.Add();
item["标题"] = this.itemtitle;
item["请假内容"] = "Content"+this.itemContent;
item["请假时间"] = "1";
item["请假人"] = Web.CurrentUser;
item.Update(); 

其中若是没有item["请假人"] = Web.CurrentUser;
List中能添加上数据, 若是有item["请假人"] = Web.CurrentUser;
就会报错。

[解决办法]
item["请假人"]的类型是SPFieldUserValue, Web.CurrentUser的类型是SPUser,显然是类型不匹配。


C# code
SPFieldUserValue qingjiaUser =   new SPFieldUserValue(   web,   Web.CurrentUser.LoginName ); item["请假人"] = qingjiaUser ; 

热点排行