RowEditing / RowEdited events

The RowEditing and RowEdited events fire when a row has been edited from the jqGrid client-side. This can happen by either end-users invoking the "Edit Row" Dialog functionality, by inline editing or by other client-side triggering of row editing.

The RowEditing event is a "before" event - it fires before the action really executes. The RowEdited event is an "after" event and fires after the row had been edited. It is up to the developer to perform the necessary actions in the RowEditing event and to update the datasource accordingly - the grid typically cannot automatically edit rows. RowEditing can also be used to perform server-side validation of the data in the new row and reject the editing if the data does not validate.

To hook RowEditing 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 RowEditing event. This will generate something similar to this in your ASPX and code behind:

<trirand:JQGrid ID="JQGrid1" runat="server" OnRowEditing="JQGrid1_RowEditing">

protected void JQGrid1_RowEditing(object sender, Trirand.Web.UI.WebControls.JQGridRowEditEventArgs e) { }

Now you have RowEditing hooked and the JQGrid1_RowEditing event handler will execute when a row is being edited. You can now use the event arguments to retrieve the data submitted for adding using the RowData name-value collection and the RowKey used to identify the row. You can retrieve data using the key from the DataField of the respective column, e.g. e.RowData["CompanyName"], e.RowData["News"], etc. Pay attention to the type of the column - RowData always returns strings, whereas your database is typically strongly typed, so you may need to check the values for validity before updating the database.

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

protected void JQGrid1_RowEditing(object sender, Trirand.Web.UI.WebControls.JQGridRowEditEventArgs e) { DataTable dt = GetData(); dt.PrimaryKey = new DataColumn[] { dt.Columns["CustomerID"] }; DataRow rowEdited = dt.Rows.Find(e.RowKey); rowEdited["CompanyName"] = e.RowData["CompanyName"]; rowEdited["Phone"] = e.RowData["Phone"]; rowEdited["PostalCode"] = e.RowData["PostalCode"]; rowEdited["City"] = e.RowData["City"]; JQGrid1.DataSource = GetData(); JQGrid1.DataBind(); }



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