开发者

Create lookup field in SharePoint 2010

开发者 https://www.devze.com 2023-03-22 14:23 出处:网络
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:

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

精彩评论

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