Use JavaScript to programmatically delete a row on client side. The Delete method will be called in a button-click event.
During this walkthrough, you will learn how to do the following:
- Configure one column of WebGrid as a button column.
- Using Client Side events to delete a row.
Prerequisites
In order to complete this walkthrough, you will need the following:
- Visual Studio 2005 Application.
Step-By-Step Instructions
To delete a record using WebGrid button
- Binding WebGrid to AccessDataSource.
- Add a column and set its ColumnType as Button.
- Make sure the column's ButtonAutoPostback property is set to false.
- Apply this script to the page:
JavaScript Copy Code <script language="javascript"> function WebGrid1_OnButtonClick(gridId, tblName, colName, cellValue) { var grid = ISGetObject(gridId); var row = grid.GetSelectedObject().GetRowObject(); row.Delete(); return true; } </script>
- Register the function to the grid's OnButtonClick client-side event.
- Run the project.