Home > LookupField, SharePoint 2010 > How to retrieve and set lookup value in SharePoint2010

How to retrieve and set lookup value in SharePoint2010

In this post, I’d like to show you how to retrieve and set the lookup value. In SharePoint2010, the lookup value you retrieve is in the format as {LookupItemID};#{LookupFieldValue}

You can download a solution here, after you deploy the SharePoint solution then you can run the console application as follows and the result is as follow:

Now, let’s look at the code to retrieve the lookup value, you can see I first retrieve the value by using the normal way of retrieving the lookup value and the value you got is 1;#Accounting. To parse the value, you need to create a SPFieldLookupValue type and you can grab the id using LookupId property and grab the value using LookupValue property.

To Set the LookupValue , you can create a SPFieldLookupValue type and assign to the lookup item or just assign the ID directly to the lookup item.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: