Link to home
Start Free TrialLog in
Avatar of sagy
sagyFlag for Israel

asked on

Adding delete button to ListVIewWebPart

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
Avatar of mccarthybri
mccarthybri
Flag of United States of America image

is your list veiw webpart a third party or homegrown webpart?  
Avatar of sagy

ASKER

No, It's the one that comes with SharePoint.
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
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
for what you want to do would require visual studio.  I dont beleive even SPD would work.
Avatar of sagy

ASKER

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.
cool deal I hope it works
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.
does this work with document librarys or just lists?
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.
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.

ASKER CERTIFIED SOLUTION
Avatar of sagy
sagy
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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