locked
Lookup field in a Data Form Part

    Question

  • Hey everyone!

    I'm having a problem here to which i cannot seem to find the answer. Perhaps you can help.

    I have a list - we'll call it 'articles' - and in that list is a lookup column called 'related articles' that allows a user to select other articles for the same list. When viewing items from this list in the default 'DispForm.aspx', the items in the lookup field are formatted beautifully, each on it's own line and linked to the item. However! When I try to build a custom Data Form Web Part (Or a custom display form even), the items from that field are plain text, with no link, separated by a semi-colon. What gives?! Why are they not linked to the items? Why can I not make that happen????? Anybody know? I've looked into the ddwrt namespace funtions, but none of them seem to apply to my situation. There must be a way to do this. It's very frustrating.

    Any help would be greatly appreciated. Thanks in advance.
    Wednesday, December 31, 2008 7:37 PM

Answers

  • Hi,

    I think it is not possible out of the box; there is a workaround for you to get the ID of the list item: create a column in your “articles” list named "lookupID”, and then attach a SPD workflow to the “articles” list, add a action to the workflow “update list item”, update the “lookupID” to the “ID” of “articles” list when the “related articles” column value is equal to the column that you looked up.

    After this, you can edit the “related articles” column in the data form web part, set its format as “hyperlink”:

    <a  href="http://sharepointserver/Lists/articles/DispForm.aspx?ID={@lookupID}">
    <xsl:value-of select"@related articles" /></a>    
     
     



    Hope it can help you.


    Xue-Mei Chang
    Friday, January 02, 2009 9:20 AM
    Moderator

All replies

  • The data is actually a name/value pair and the standard forms just handle it for you.  For the display you should be able to just code the link and pass in the ID provided.  I've worked with it in custom web parts, data views, etc.  I haven't done a custom data form with one, but I imagine it would be much more difficult than a non-linked field.
    Wednesday, December 31, 2008 9:34 PM
  • Thank you so much for the reply!

    Unfortunately, I can't seem to locate the ID for the items in the lookup field. I'm not sure that it's returning that value. I can find the ID for the main item that's displaying, but I think it's only returning the 'Title' field for items in the lookup column. Does that make sense? Can you help mt to find the ID of the individual lookup-field items?
    Thursday, January 01, 2009 12:04 AM
  • Hi,

    I think it is not possible out of the box; there is a workaround for you to get the ID of the list item: create a column in your “articles” list named "lookupID”, and then attach a SPD workflow to the “articles” list, add a action to the workflow “update list item”, update the “lookupID” to the “ID” of “articles” list when the “related articles” column value is equal to the column that you looked up.

    After this, you can edit the “related articles” column in the data form web part, set its format as “hyperlink”:

    <a  href="http://sharepointserver/Lists/articles/DispForm.aspx?ID={@lookupID}">
    <xsl:value-of select"@related articles" /></a>    
     
     



    Hope it can help you.


    Xue-Mei Chang
    Friday, January 02, 2009 9:20 AM
    Moderator
  • Thank you, Xue-Mei Chang!

    That solution seems like it would work beautifully if the lookup field only allowed one value, but unfortunately, mine needs to allow multiple values. I'm wondering if your workaround would work for that? I'm thinking it wouldn't.

    This problem seems so strange because it's obviously possible to format these mutiple-value lookup fields as links to the items, as the default DispForm.aspx has them formatted that way. Urgh. Frustrating...
    Monday, January 05, 2009 5:49 PM
  • Hi,

    I found another way :http://blogs.msdn.com/frontpoint/archive/2005/04/15/408672.aspx

    But I think it is not possible for the multiple value lookup fields.
    One way that it can be accomplished is by splitting the multivalue string and creating the links manually.

    Xue-Mei Chang
    Tuesday, January 06, 2009 8:30 AM
    Moderator
  • I know a rich text field could have multiple links.
    One way may be to have code populate that field with the lookup items, formatted with the links.
    Greg

    • Proposed as answer by Quincy Thomas Tuesday, February 10, 2009 3:02 PM
    Tuesday, January 06, 2009 8:56 PM
  • After searching for some hours, I found a solution in SharePoint Designer itself.

    Just open the DispForm, right-click the FormField of the column where the lookup hyperlink should be and format the item as List Form Field.
    The same pull-down menu box as in Edit- and NewForm will appear. Search in the code (split mode and click the form field) for the code from the form field.

    Change controlmode="Edit" to controlmode="Display"

    It worked great for me...

    Good luck on it.

    Kindest regards,

    Quincy Thomas


    QT
    Tuesday, February 10, 2009 3:13 PM