[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Adding delete button to ListVIewWebPart

Posted on 2009-12-22
13
Medium Priority
?
2,178 Views
Last Modified: 2012-06-27
Hello,

I have a ListViewWebPart that displays the user's documents library.

Is there a way to add a delete button on each row that would simulate the delete function from the context menu?

Thanks,
Sagy
0
Comment
Question by:sagy
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 12

Expert Comment

by:mccarthybri
ID: 26103384
is your list veiw webpart a third party or homegrown webpart?  
0
 

Author Comment

by:sagy
ID: 26103449
No, It's the one that comes with SharePoint.
0
 
LVL 12

Expert Comment

by:mccarthybri
ID: 26103510
okay got it.

wel you could ensure the veiw have the name with the edit function so they could just do the drop down and edit.  I knwo thats not what your looking for
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 12

Expert Comment

by:mccarthybri
ID: 26103517
so if you ad the edit field they could click on that and it would bring up the item with edit in it.  let me tinker a bit more
0
 
LVL 12

Expert Comment

by:mccarthybri
ID: 26103536
for what you want to do would require visual studio.  I dont beleive even SPD would work.
0
 

Author Comment

by:sagy
ID: 26103604
Hi,

Thanks for the reply.

I found a solution that allows to add a button or a hyperlink to a list, here:

http://www.moss2007.be/blogs/vandest/archive/2008/06/20/view-action-button.aspx

I'm going to try it ans see if it helps.
0
 
LVL 12

Expert Comment

by:mccarthybri
ID: 26103726
cool deal I hope it works
0
 

Expert Comment

by:kieriosity
ID: 26105028
This is how I added a delete button to the list view:

1.      Open the page in SharePoint Designer
2.      Convert the list webpart to a data view
3.      Right click in a row that will be adjacent to your column and select insert column to the left or right
4. Add a button to the column. I use the form controls button under the Toolbox. You can find this by clicking insert, HTML, more HTML tags from the top menu. This will load the toolbox on the right side of designer.
5.      Right click on the newly created button, and select Form Actions
6.      Add a custom action to the current actions, and click OK
7.      Edit the button javascript

From:
onclick="javascript: {ddwrt:GenFireServerEvent('__workflowStart={{52BBE42F-1813-4BB8-8B61-160BEF2E57B5},New,{34C0E78A-C41C-4F8C-BA6C-D2BE48CB5907},}')}" />

To this:
onclick="javascript: {ddwrt:GenFireServerEvent(concat('__workflowStart={{52BBE42F-1813-4BB8-8B61-160BEF2E57B5},New,{34C0E78A-C41C-4F8C-BA6C-D2BE48CB5907},ID=',@ID,'}'))}" />

Notice that I added a concat statement and set and ID parameter equal to the current ID via  @ID.  The custom action will automatically generate the workflow and list IDs, and they will be different from the ones above, but you dont need to worry about those.
8.      Reopen the form actions (step 5), click custom action and click the settings button
9.      Create a workflow variable, name it ID and set its type to List Item ID (this should be the same name as the ID in your javascript statement, so if have changed the name there, change it here as well)
10.      Finally, create a Delete Item action. Choose the list for which you created the button, and set the lists ID to the Variable: ID

The advantage to this approach is that you can add any number of workflow steps to the button action. For example, you can have an email sent when an item is deleted or update some data, or archive the data prior to deletion.

Hope this helps.
0
 
LVL 12

Expert Comment

by:mccarthybri
ID: 26105045
does this work with document librarys or just lists?
0
 

Expert Comment

by:kieriosity
ID: 26105188
Yes, it works for document libraries as well; I just tested it. However, did notice that when I was testing it that after I edited the workflow, the javascript changed. So wait to do step 7 until the end.
0
 

Expert Comment

by:kieriosity
ID: 26106183
I'm going to repost my original solution as there were some helpful details that I think are worth including. Again, this will work for both lists and document libraries.

1.    Open the page in SharePoint Designer
2.    Convert the list webpart to a data view
3.    Right click in a row that will be adjacent to your column and select insert column to the left or right. Note: this only works if you have an item in the list or document library. If you do not have an item in the list, then you will need to manually ad the table column to the table.
4.    Add a button to the new column. I use the form controls button under the Toolbox. You can find this by clicking insert, HTML, more HTML tags from the top menu. This will load the toolbox on the right side of Designer.
5.    Double click on the button and change the value/label to Delete. You can also set the button name to your preference. Click OK.
6.    Right click on the button, and select Form Actions.
7.    Add a custom action to the current actions. Click OK.
8.    Highlight custom action and click the settings button
9.    Create a workflow variable, name it ID and set its type to List Item ID (the variable should be the same name as the ID in your javascript statement (step 15), so if you plan to change the name there, change it here as well)
10.    Create a Delete Item action. Choose the list on which you created the button, and set the lists ID to the Variable: ID. Click finish to complete the workflow.
11.    With the Form Actions still open, add the Navigate to page action.
12.    Highlight Navigate to page action, and click settings.
13.    Browse to the page on which you created the data view. (This will ensure that the page is refreshed after you delete the item. This must be the second action in the list). Click OK.
14.    Click OK again, to exit Form Actions.
15.    Click the button to highlight the button code in the code view. Edit the button javascript

From:

onclick="javascript: {ddwrt:GenFireServerEvent('__workflowStart={{52BBE42F-1813-4BB8-8B61-160BEF2E57B5},New,{34C0E78A-C41C-4F8C-BA6C-D2BE48CB5907},}')}" />

To this:

onclick="javascript: {ddwrt:GenFireServerEvent(concat('__workflowStart={{52BBE42F-1813-4BB8-8B61-160BEF2E57B5},New,{34C0E78A-C41C-4F8C-BA6C-D2BE48CB5907},ID=',@ID,'}'))}" />

Notice that I added a concat statement and set and ID parameter equal to the current ID via  @ID.  The custom action will automatically generate the workflow and list IDs, and they will be different from the ones above, but you dont need to worry about those.

0
 

Accepted Solution

by:
sagy earned 0 total points
ID: 26118688
Thank you all for helping.

I ended up creating a custom field type which adds a button on each row. This button fires a javascript code that redirects to a custom aspx page, passing it the required parameters ListID and ItemID.
This page performs the item delete on its load event and redirects back to the calling page.

I followed the concept described at: http://www.moss2007.be/blogs/vandest/archive/2008/06/20/view-action-button.aspx

Thanks,
Sagy

0
 
ID: 37682970
kieriosity's solution is great! I am using this to submit dataformwebpart parameter values to a stored procedure on an external sql server db. I need to send a second value pair for a second stored procedure in the same workflow. Any ideas? I am not having any joy with finding the right javascript to put in the second value pair.

I know this is an old post but would love some help.

Thanks
Russell
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month19 days, 14 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question