I have an AJAX enabled grid bound to a sqlDataSource. If an exception occurs for any reason while the user is adding/updating/deleting data in this grid, what is the standard practice for getting this message back to the user? Currently my grids just keep working as if nothing has gone wrong.
BTW, I can see exception data being passed into the sqlDataSource_Updating event.
Thanks!
Hi,
Try this. I hope it helps.
Regards,
Harun#?
function UltraWebGrid1_XmlHTTPResponseHandler(gridName, rowId, gridResponse){ var ResponseObj = gridResponse ; // igtbl_getGridById(gridName).XmlResponseObject; if (ResponseObj.ReqType==igtbl_reqType.UpdateRow || ResponseObj.ReqType==igtbl_reqType.AddNewRow || ResponseObj.ReqType==igtbl_reqType.DeleteRow ) { alert(ResponseObj.StatusMessage); } }
Thanks for the reply. That is a piece of the puzzle, but that client-side event fires before the server-side SqlDataSource Update event fires, so it's not able to capture or any error messages. My solution was to not let the grid call the SqlDataSource directly, instead I do that myself so I can return the message. My Update methods look something like this (see below). The "PopulateParameters" method helps to make this function a little more generic and reduces the amount of code, but it assumes the columnKey will be the same as the named parameters in the SqlDataSource. (works the same for Add and Delete).
-Walter
protected void UltraWebGrid2_UpdateRow(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e) { try { PopulateParameters(sourceChains.UpdateParameters, e.Row);
sourceChains.Update(); ((UltraWebGrid)sender).ClientResponse.ResponseStatus = XmlHTTPResponseStatus.Success; ((UltraWebGrid)sender).ClientResponse.StatusMessage = "Record Updated."; } catch (Exception ex) { UltraWebGrid2.DataBind(); ((UltraWebGrid)sender).ClientResponse.ResponseStatus = XmlHTTPResponseStatus.Fail; ((UltraWebGrid)sender).ClientResponse.StatusMessage = "Unable to update record. <br><Br>The following error occurred: " + ex.Message; }
e.Cancel = true; UltraWebGrid2.DataBind();
}
private void PopulateParameters(ParameterCollection parameterCollection, UltraGridRow row) { foreach (Parameter p in parameterCollection) { if (row.Cells[row.Band.Columns.FromKey(p.Name).Index].Value == null) { p.DefaultValue = null; } else { p.DefaultValue = row.Cells[row.Band.Columns.FromKey(p.Name).Index].Value.ToString(); } } }