网上有,但是是错误的,稍微改一下,就可以了

第一个方法是要更新的item,其中 _fieldname 为要更新的lookup字段名字,_lookupValue为要更新的值。

public void SetFieldValueLookup(SPListItem _item, string _fieldname, string _lookupValue)
        {
            if (_item != null)
            {
                SPFieldLookup field = _item.Fields.GetFieldByInternalName(_fieldname) as SPFieldLookup;
                _item[_fieldname] = GetLookupValue(_item.Web, field, _lookupValue);
                _item.Update();
            }
            else
            {
                _item[_fieldname] =null;
            }
        }

public SPFieldLookupValue GetLookupValue(SPWeb _web, SPFieldLookup _field, string _lookupvalue)
        {
            string queryFormat = @"<Where><Eq><FieldRef Name='{0}' /><Value Type='Text'>{1}</Value></Eq></Where>";
            string queryText = string.Format(queryFormat,  _field.LookupField, _lookupvalue);
            SPList lookupList = _web.Lists[new Guid(_field.LookupList)];
            SPQuery query = new SPQuery();
            query.Query = queryText;
            SPListItemCollection lookupItems = lookupList.GetItems(query);

if(lookupItems.Count > 0)
            {
                int lookupId = Convert.ToInt32(lookupItems[0][SPBuiltInFieldId.ID]);
                return new SPFieldLookupValue(lookupId, _lookupvalue);
            }
            else
            {
                return null;
            }

}

用这个方法就可以了._field.LookupField是关联另一个item的字段

sharepoint 2010 FieldLookup 的更新方法的更多相关文章

  1. SharePoint 2010 常用技巧及方法总结

    1.代码调试确定进程cd c:\windows\system32\inetsrvappcmd list wppause注:保存成批处理文件,查看进程.bat,用的时候双击即可 2.类似列表新建打开方式 ...

  2. sharepoint 2010 页面添加footer方法 custom footer for sharepoint 2010 master page

    转:http://blog.csdn.net/chenxinxian/article/details/8720893 在sharepoint 2010的页面中,我们发现,没有页尾,如果我们需要给页面添 ...

  3. SharePoint 2010升级到sharePoint 2013后,人员失去对网站的权限的原因及解决方法。The reason and solution for permission lost after the upgrading

    昨天碰到了一个问题,一个网站在从SharePoint 2010升级到SharePoint 2013后,人员都不能登录了,必须重加赋权,人员才能登录,这样非常麻烦. 原因:是认证方式的问题.在Share ...

  4. 复制转移sharepoint 2010 designer做的list workflow的方法

    SharePoint 2010 designer做的workflow都有一个导出到visio的功能,但是如果是list workflow一般都是不可重用的,即使导出了,也是导不进目标站点或者list的 ...

  5. SharePoint 2010 以Jquery Ajax方式更新SharePoint列表数据!

    之前本人的博客介绍了<sharepoint 2010自定义访问日志列表设置移动终端否和客户端访问系统等计算列的公式>,那如何通过Jquery提交访问日志到自定义的SharePoint的访问 ...

  6. SharePoint 2010 "客户端不支持使用windows资源管理器打开此列表" 解决方法

    SharePoint 2010 在“库”--“库工具”,有一个“使用资源管理器打开”的按钮,点上去报“客户端不支持使用windows资源管理器打开此列表”.如图: 解决方案:在“开始”--“管理工具” ...

  7. [转]SharePoint 2010/2013 使用Javascript来判断权限的三种方法

    本文讲述SharePoint 2010/2013 使用Javascript来判断权限的三种方法的实现方式及其优缺点. 1. 根据用户所在的SharePoint组(比如用户在Leader 组才可以使用审 ...

  8. 清理SharePoint 2010的SQL Server 2008 R2日志数据库的方法!

    //来源:http://www.cnblogs.com/nbpowerboy/p/3380079.html 公司用SharePoint 2010已有三年多的时间了,上BPM项目也有2年多的时间,之前供 ...

  9. SharePoint 2010 最佳实践学习总结------第1章 SharePoint Foundation开发基础

    ----前言 这段时间项目出在验收阶段,不是很忙,就潜心把SharePoint学一下,不求有多深刻,初衷只是先入门再说.后续会发布一系列的学习总结.主要学习的书籍为<SharePoint2010 ...

随机推荐

  1. 查看详细linux系统信息的命令和方法

    查看内存大小: cat /proc/meminfo |grep MemTotaluname -a # 查看内核/操作系统/CPU信息的linux系统信息命令head -n 1 /etc/issue # ...

  2. MySql8最新配置方式(完美)

    下载MYSQL8 地址:https://www.mysql.com/downloads/ 1.滑动网页到最下面,选择Community (GPL) Downloads » 2.选择MySQL Comm ...

  3. poj3040 发工资(贪心)

    题目传送门 题目大意:给一个人发工资,给出不同数量不同面额,(大面额一定是小面额的倍数),问最多能发几天,(每天实发工资>=应发工资). 思路:首先,将大于等于c的面额的钱直接每个星期给奶牛一张 ...

  4. codeforces 620D Professor GukiZ and Two Arrays

    #include <bits/stdc++.h> using namespace std; + ; const long long inf = 1e18; int n, m; long l ...

  5. C# 事务提交(非数据库)

    .Net 2.0开始支持 static void Main(string[] args) { using (TransactionScope ts = new TransactionScope()) ...

  6. NPOI2.0导出excel之添加样式、边框和表头

    //优化后导出excel public System.IO.Stream ExcelStream(string search) // { var orderBusiniss = Containers. ...

  7. java——修改txt文件中某一行的内容

    今天无意间看到java.io中有一个类:RandomAccessFile,可以在文件的任意位置进行读写操作,想到我之前写的一个小项目,想在txt中修改某一行的内容,都是从头遍历txt文件,修改这一行的 ...

  8. 转 ogg issue

    1.http://www.dbdream.com.cn/2013/05/17/ogg-00446%E9%94%99%E8%AF%AF%E8%A7%A3%E5%86%B3/ OGG-00446错误解决 ...

  9. Unity 在Inspector面板,脚本前面的激活对勾

    写个脚本,把它挂在一个游戏对象上: using System.Collections; using System.Collections.Generic; using UnityEngine; pub ...

  10. vue中遇到的坑

    如何解决在vue中替换图片.一个使用base64,而我们使用zepto之后,src找不到资源,因为已经打包了,难道强行写base64. 1. 引入文件时语法很重要! import "Foot ...