开发者

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 er开发者_如何学JAVAror


Internally, SharePoint stores these references like this: NumericID;#DisplayValue i.e.

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜