开发者

Create lookup field in SharePoint 2010

How to add lookup column in List1 and bind it with SomeField from List2, and then fill this 开发者_C百科lookup column with plain text (only use code)?


Here's the code to create a lookup field:

var list = web.Lists["List1"];    
var targetList = web.Lists["List2"];
var fieldName = list.Fields.AddLookup("My Lookup", targetList.ID, false);
var field = list.Fields.GetFieldByInternalName(fieldName) as SPFieldLookup;
field.LookupField = "SomeField";
field.Update();

To update the lookup field you set it to the item ID of the item in the target list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜