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!
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.
@Pete,
thank you for pointing! The code was fixed.
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
Is there a way to hide this delete button when doing an inline edit (the same way the edit button disappears)?
Thanks,
Tim
@Tim,
this won’t be that easy as you would need to intercept inline edit click. We do not have an API for this.
Can we delete only certain columns/fields from a row using the same method?