简体   繁体   English

如何在自定义ASPX页面中使用sharepoint:lookupfield控件

[英]How to use sharepoint:lookupfield control in a custom aspx page

I've searched four several hours and came up empty. 我已经搜索了四个小时,却空了出来。 Hopefully someone can provide me with some example code. 希望有人可以向我提供一些示例代码。

I'm making a custom page in sharepoint, displaying/editing data about an entry in the document list named "Documents". 我正在sharepoint中创建一个自定义页面,以显示/编辑有关文档列表中名为“文档”的条目的数据。 The document's content type has a custom column of type Lookup. 文档的内容类型具有一个类型为Lookup的自定义列。 The Lookup is done in the list named "Case", referring the column named "Title" 在名为“案例”的列表中完成查找,引用名为“标题”的列

I am trying to use the SharePoint:LookupField component in the following way in my .aspx file: 我试图以下列方式在.aspx文件中使用SharePoint:LookupField组件:

<SharePoint:LookupField ID="lookupCase" runat="server" ControlMode="New"></SharePoint:LookupField>

In my code behind, I have the following: 在后面的代码中,我具有以下内容:

lookupCase.ListId = SPContext.Current.Web.Lists["Case"].ID;
lookupCase.FieldName = SPContext.Current.Web.Lists["Case"].Fields.TryGetFieldByStaticName("Title").InternalName;

but nothing renders. 但没有任何结果。

Any ideas? 有任何想法吗?

Thanks in advance, Wouter 在此先感谢Wouter

I fiddled more around and found the solution. 我摆弄更多,找到了解决方案。

I was doing two things wrong: 我做错了两件事:

1) I have to pass in the Item ID and the List ID in a URL parameter, such as: 1)我必须在URL参数中传递Item ID和List ID,例如:

ID=7&List={0845CEAB-A577-4FBD-8CEE-21A6BE08ED7E}

I'm guessing that this is because this component looks up some data in the SPContext. 我猜这是因为此组件在SPContext中查找了一些数据。

2) In the code behind, I was referring the looked-up table, whereas I have to refer the looking-up table: 2)在后面的代码中,我引用的是查找表,而我必须引用的是查找表:

lookupCase.ListId = SPContext.Current.Web.Lists["Documents"].ID;
lookupCase.FieldName = SPContext.Current.Web.Lists["Documents"].Fields.TryGetFieldByStaticName("CasD").InternalName;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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