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;"
              onclick="javascript:window.location='/{@FileDirRef}/Forms/EditForm.aspx?ID={@ID}&amp;source='+window.location">
   <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. 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?

  2. 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:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s