What I wanted to do is adding a delete button to each item in the listview to delete a record directly from the overview. Sharepoint has an edit button that can be inserted by adding the “Edit” column in the view editor. It’s a shame that Sharepoint doesn’t have a similar option for deleting. This doesn’t mean it is impossible, it’s just not that easy, here you go:
Open SPD(Sharepoint Designer) and go to the list you want to add the button to and open the AllItems.aspx
duplicate the ListViewWebPart by copying the following code and pasting it directly after itself.
<WebPartPages:ListViewWebPart runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{28B30FD4-BA90-4FFE-8EA6-2608237AF16B}" > ... ... </WebPartPages:ListViewWebPart>
<IsVisible>true</IsVisible>
to
<IsVisible>false</IsVisible>
Be sure that the first listform is now visible when you go to the list with your browser.
In SPD rightclick the first listview and click “Convert to XSLT Data View”. You can now edit every column, value and formula. Create a new column where you want the delete button to be. In my case I want it next to the edit button so I rightclick that column and insert a column to the right.
In the newly created column you can change the header to “Delete” or “Remove” or whatever you want.
Now we need to locate the empty cell in code view. Assuming you have split view we’re going to select only the first two cells (not the header) of the newly created column, you see the code view jump. Now locate the empty
<TD Class="{$<SomeId>}"></TD>
or
<TD Class="{$<SomeId>}">
<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&nbsp;</xsl:text>
</TD>
in your selected code and replace it with
<TD Class="{$<SomeId>}"> <xsl:choose> <xsl:when test="ddwrt:IfHasRights(4)"> <a href="javascript: {ddwrt:GenFireServerEvent(concat('__cancel;__delete={ID=',@ID,'};__commit'))}"><img border="0" alt="Edit" src="/_layouts/images/delete.gif" /></a> </xsl:when> <xsl:otherwise> <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&nbsp;</xsl:text> </xsl:otherwise> </xsl:choose> </TD>
Now we are done, save and enjoy deleting! =)
Update
For them who want to have a conformation box before deleting just insert this code instead of the above:
<TD> <xsl:choose> <xsl:when test="ddwrt:IfHasRights(4)"> <a href="javascript: if(confirm('Are you sure you want to delete?')){ddwrt:GenFireServerEvent(concat('__cancel;__delete={ID=',@ID,'};__commit'))}"><img border="0" alt="Edit" src="/_layouts/images/delete.gif" /></a> </xsl:when> <xsl:otherwise> <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&nbsp;</xsl:text> </xsl:otherwise> </xsl:choose> </TD>
one word…..legend.
thanks for the kool tip
Can we have this for SharePoint 2010. I noticed there is no class=someid for the td fields and this code does nothing in a 2010 data form web part
I am sorry I made a mistake. it works in SP 2010 too without the need to add an ID for the TD tag
This is awesome thanks! This worked fine for me until I installed KB2844286 and then all of my views could not be rendered for my pages. Long storey, but I wound up recreating my webpart viewes. Since then I have not been able to use your delete tool, keep getting an error:
The data source control failed to execute the delete command. 0c95a215-12cc-4a35-aeda-730e5e1d6aeb
Any suggestions. Nothing changed with my data or permission, just the viewes got messed up wen I installed the KB. Thanks!
Have you Configured same functionality on SharePoint 2013?
nope, not yet. Are you having any difficulties?