RowDeleting / RowDeleted events

The RowDeleting and RowDeleted events fire when a row is being deleted from the jqGrid client-side. This can happen by either end-users invoking the "Delete Row" Dialog functionality, or by other client-side triggering of row deleting.

The RowDeleting event is a "before" event - it fires before the action really executes. The RowDeleted event is an "after" event and fires after the row had been deleted. It is up to the developer to perform the necessary actions in the RowDeleting event and to update the datasource accordingly - the grid typically cannot automatically delete rows.

To hook RowDeleting event, just select your JQGrid instance in Visual Studio.NET design time, select Properties (or click F4), then in the Properties window switch to Events and double click the RowDeleting event. This will generate something similar to this in your ASPX and code behind:

<trirand:JQGrid ID="JQGrid1" runat="server" OnRowDeleting="JQGrid1_RowDeleting">

protected void JQGrid1_RowDeleting(object sender, Trirand.Web.UI.WebControls.JQGridRowDeleteEventArgs e) { }

Now you have RowDeleting hooked and the JQGrid1_RowDeleting event handler will execute when a row is being deleted. You can now use the event arguments to retrieve the RowKey used to identify the row.

Here is sample code for updating the database in the RowDeleting event using ADO.NET DataTable. Same principles apply for arbitrary datasource.

protected void JQGrid1_RowDeleting(object sender, Trirand.Web.UI.WebControls.JQGridRowDeleteEventArgs e) { DataTable dt = GetData(); dt.PrimaryKey = new DataColumn[] { dt.Columns["CustomerID"] }; DataRow rowToDelete = dt.Rows.Find(e.RowKey); if (rowToDelete != null) dt.Rows.Remove(rowToDelete); JQGrid1.DataSource = GetData(); JQGrid1.DataBind(); }



  Last Updated: 11/1/2009 | © Trirand, 2009