Data View Web Part: Add an Edit Properties Link which Returns to the Link Source

The Data View Web Part is a great component to use to create user interface elements in SharePoint as an alternative to the Document Library / List UI. But you still want to give users access to the relevant List Forms; Add, Edit, Display.  

This is easy enough to do by creating a link to the form required, for example the edit properties form as shown:

      <a href='http://server/site/Document Library/forms/EditFom.aspx?ID=1'>Edit Properties</a>

However when clicking OK or Cancel on the List Form, by default you are redirected to the parent list or document library. In order to be redirected to another location after clicking OK or Cancel you can make use of the “source” query string parameter. Essentially you provide the redirect location URL as the source query string parameter in the URL of the List Form. This is well documented and many SharePoint forms accept this parameter. 

Now, back to our Data View Web Part, to create our link to the edit properties form for an item and have it return to the page with the DVWP instance on it we need to create an image link to the correct form URL and append to it the URL of the current page. 

The snippet below will do just that;

   <span style="cursor:pointer; padding-right:8px;"
   <img src="/_layouts/images/edititem.gif" alt="edit properties" align="absmiddle" /></span>

The snippet creates a span with an OnClick handler and embedded image. The OnClick handler navigates to the URL created from;

  1. @FileDirRef – the server relative path to the (document library in this case) item
  2. The edit properties form (/forms/EditForm.aspx)
  3. The ID query parameter supplying the ID of the item using the @ID field
  4. The source query parameter using the current location supplied by window.location.
DVWP with Link to Edit Properties

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

10 thoughts on “Data View Web Part: Add an Edit Properties Link which Returns to the Link Source

  1. There is a problem with this. The link won’t work when the item is in a folder.

    I am trying to work out the solution at the moment.


  2. Great post! Just wondering how to deal with having to check out the item first. I keep getting an error message to that regard.

    Maybe it would be better simply to add the pull down menu on the title field similar to what exisits in the document library list. Not sure how to do that exactly. Would you have any thoughts?

  3. Iain, the snippet would be inserted into the XSLT code which is part of the DVWP markup, in the section which renders each list item.

  4. Thanks, works like a charm.

    One question, will users who don’t have edit permissions on the item see this link?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.