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". The document's content type has a custom column of type 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:
<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
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:
ID=7&List={0845CEAB-A577-4FBD-8CEE-21A6BE08ED7E}
I'm guessing that this is because this component looks up some data in the SPContext.
2) In the code behind, I was referring the looked-up table, whereas I have to refer the looking-up table:
lookupCase.ListId = SPContext.Current.Web.Lists["Documents"].ID;
lookupCase.FieldName = SPContext.Current.Web.Lists["Documents"].Fields.TryGetFieldByStaticName("CasD").InternalName;
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.