How to add a “Delete” button to each row in grid

By default PHPRunner/ASPRunner.NET provide "Delete selected" functionality. In some cases you need to be able to delete records individually. In this tutorial we will show how to add a delete button to each record. We will also show how to make it look as a regular edit/copy/view buttons.

1. Proceed to the List page in Page Designer and insert a button. Move it to one of grid columns. Set button style to "link-button" and choose icon "glyphicon-remove" as appears on a screenshot below.


2. Now lets edit button's code. We want to ask for a deletion confirmation, delete record and reload the page.

ClientBefore event:

if (confirm("Do you want to delete this record?"))
return true;
else 
return false;

In Server event you will need to specify correct table and key column name. In our case table name is categories and key column name is CategoryID.

Server event PHP code:

$record = $button->getCurrentRecord();
$data = array();
$data["CategoryID"] = $record["CategoryID"];
DB::Delete("categories", $data );

Server event C# code:

XVar record = button.getCurrentRecord();
dynamic data = XVar.Array();
data["CategoryID"] = record["CategoryID"];
DB.Delete("categories", data );

Client After event:

location.reload();

This is it. Enjoy!

3 comments to How to add a “Delete” button to each row in grid

  • Pete K

    Can you double-check the C# code? It does not compile for me as written. I tried removing the third line which appears to be a mistake, and changed pageObject.getCurrentRecord(); in the first line to button.getCurrentRecord();. After these changes, the code compiles and no errors are generated upon running it, but the record does not get deleted. I did update the table and PK names.

  • admin

    @Pete,

    thank you for pointing! The code was fixed.

  • Tuong

    If it did not delete then please try changing

    DB.Delete(“categories”, data );

    to

    DB.Delete(“dbo.categories”, data );

    If you are using MS SQL

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>