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;
The snippet creates a span with an OnClick handler and embedded image. The OnClick handler navigates to the URL created from;
- @FileDirRef – the server relative path to the (document library in this case) item
- The edit properties form (/forms/EditForm.aspx)
- The ID query parameter supplying the ID of the item using the @ID field
- The source query parameter using the current location supplied by window.location.
10 thoughts on “Data View Web Part: Add an Edit Properties Link which Returns to the Link Source”
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.
Thanks for the feedback, I don’t use folders, but if you have a solution I’d appreciate it if you’d share it.
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?
Thanks for the post.
What I am not sure about is where I post the snippet.
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.
Thanks, works like a charm.
One question, will users who don’t have edit permissions on the item see this link?
In short, yes, although the xlst could be modified to only show the edit link if the user has edit permissions.