简体   繁体   中英

Sharepoint update Lookup Column

I am trying to update a Lookupvalue field "Items" via the SharePoint object model.

"Products" is a column in one list which is used as a lookup column to another list in field "Items".

In my webpart i have dropdown of Items now

string strItems = ddlItems.SelectedValue.ToString();

item["Items"] = new SPFieldLookupValue("strItems");

item.Update();

However, this is causing an error

Internally, SharePoint stores these references like this: NumericID ;#DisplayValue ie

145;#Soup
12;#Cake
874;#Steak

That is the kind of thing that should be in the constructor to SPFieldLookupValue. Or if it is more helpful, use the variant of the constructor that takes an int id and string display value.

More info is laid out here: http://blogs.msdn.com/b/sridhara/archive/2007/08/25/update-quot-lookup-quot-fields-in-sharepoint-2007.aspx

You need to set the Items column to the ID of the SPItem represented by the product. You could do this by setting the DataTextValue of your dropdown to ID and then using the SelectedValue. You could also do a CAML query when a new item is selected in the dropdown.

You can find more information at the bottom of this blog post:

http://weblogs.asp.net/bsimser/archive/2005/05/13/406734.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM