Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1465
e.Cancel still updates grid
posted

Hello.

Version 10.3.20103.1013.

The WebDataGrid does not reflect the underlying ObjectDataSource on an Update.

I tried ClearDataSource but that clears the DataKeys. I would then have to programmatically reset the grid control. That seems silly.

Also, cancelling the RowUpdating event (e.Cancel = True) has no effect on the grid: the values the user entered are still there.

What gives?

Mike

  • 33839
    Suggested Answer
    posted

    Hi Mike,

    I'm not sure what is up with the ObjectDataSource.  For that one, I may need a sample.

    As to your second issue.  It seems to be the way that editing is done.  However, with some simple code, you can work around this.  On the server in the row updating event, you save off the old values in the grid response object.  You could save the value and text to get it all right on the client (we do when the update succeeds)

    protected void WebDataGrid1_RowUpdating(object sender, RowUpdatingEventArgs e)

        {

            e.Cancel = true;

            this.WebDataGrid1.CustomAJAXResponse.Tag = "cancelEdit";

            this.WebDataGrid1.CustomAJAXResponse.Message = e.Row.Index.ToString();

            foreach (string key in e.Values.Keys)

            {

                object[] vals = new object[3];

                vals[0] = key;

                vals[1] = e.OldValues[key];

                vals[2] = this.WebDataGrid1.Columns[key] != null ? this.WebDataGrid1.Columns[key].FormatValue(e.OldValues[key]) : null;

                this.WebDataGrid1.CustomAJAXResponse.AdditionalProperties.Add(key, e.OldValues[key]);

            }

        }

    Then handle AJAXResponse="comeback" client event for the grid.

    function comeback(grid, args)

            {

                var responseObj = args.get_gridResponseObject();

                if (responseObj.Tag == "cancelEdit")

                {

                    var row = grid.get_rows().get_row(responseObj.Message);

                    for (var key in responseObj.AdditionalProperties)

                    {

                        if (row.get_cellByColumnKey(key))

                            row.get_cellByColumnKey(key).set_value(responseObj.AdditionalProperties[key]);

                    }

                }

            }

    This should get you started.

    regards,

    David Young