As a programmer who wears many hats I only get to work in the .net environment using the infragistics tools every blue moon. This is something I've known how to do once but can't figure out how to do it now. I'm using ultrawebgrid Version=7.1.20071.1050 and VS 2003 in clr 1.1. Anyway...
I'm using several ultrawebgrids already on a page and I only want them to update batch, not update after every row is added or modified. I've managed to do that. NOW I have to add another grid to a page and I want the same behavior but I can't seem to find how to keep it from doing a postback after every row is changed. I know this is simple but I somehow blocked on this.
Please help and thanks for your patience with some one out of the loop and behind the curve.
Hello.
To make the WebGrid perform batch updates, you simply handle one of the batch events, such as UpdateRowBatch, AddRowBatch, or DeleteRowBatch. There are no properties on the grid that tell what type of updates to do. Instead, you do this by handling events. If the batch events are handled, then the grid will not post back when you enter data into a row and then set focus to a different row. That would be the behavior if you handled the UpdateRow event instead.
With batch updates, some other control on the form has to intitiate a postback. Usually, most people use a button that says "Update", or "Accept Changes" or "Commit", or something else to that effect. However, any time the page posts back the various batch events will fire, regardless of the control that initiated it. The events fire once per row that is being updated, added, or deleted.
Please let me know if there is anything else I can do for you.
My code is handling UpdateRowBatch, however it is firing twice even though I have updated only one cell. Within the UpdateRowBatch the code is re-generating the dataset and binding it to the grid -- could that be the problem? If so any ideas on a work-around?
Thanks.
My bad...
I had both
//code behind: this.uwgGeneric.UpdateRowBatch += new UpdateRowBatchEventHandler(this.uwgGeneric_UpdateRowBatch);
and
//aspx: OnUpdateRowBatch ="uwgGeneric_UpdateRowBatch"
Sorry for the trouble!
Thanks for your help.
I am positive I am only updating one row (1 cell) -- not even clicking in other rows. And I commented out the method that generates the dataset and grid binding. I double-checked everything and it is only one post-back but UpdateRowBatch is firing twice?!
UpdateRowBatch should fire once per row that is being updated. It doesn't matter how many of the cells on that row have been modified. if only one row is modified, then it should fire once. Try adding this code to the event handler after using (or Imports in VB) the System.Diagnostics namespace. :
Debug.WriteLine("---------------------------------------------------------------------------------------------------------");
Debug.Indent();
Debug.WriteLine("UltraWebGrid1_UpdateRowBatch");
Debug.WrtieLine(string.Format("Value of Primary Key: {0}", e.Row.Cells["PrimaryKey"].Value.ToString()));
Debug.Unindent();
In this example, the PrimaryKey is just something I put in there to indicate the key of the cell that is the data key field. The idea here is to look at the output window in Visual Studio to see what is going on. This way, you can verify how may time the event fires and the exact rows that are being updated.
Since you are performing batch updates, I would not re-bind the grid in the event. What you should do is simply update the dataset with the new data from e.Row, which is the UltraGridRow object being updated. After UpdateRowBatch has finished, you will have a modified dataset containing all the new information the users entered on the client. Once this process is done, you can update your database in one shot.
There are two ways of doing this. One way is to handle the grids UpdateGrid event. This event fires once after all of the update, add, and delete row events have fired....batch or regular. So, when you hit this event, you can be certain that all of the updating/adding/deleting has completed. This is a great time to open your connection to Sql and send the changes to the server. This way, you open one connection to Sql, pass all the changes through, and then close the connection. If for some reason a Sql exception is thrown, (you would want to put this all in a try/catch/finally block), you can simply call the RejectChanges method on the data set and go back to the way it was prior to the updates. If it is successful, you can then call AcceptChanges and lock them all in. If you want to re-bind, then this is the time to do it after you know that all of your changes made it back to the Sql server.
You could also execute this code in a button click event if you wanted to. With batch updates, people typically put an ASP.NET server button on the form that will say "Update", or "Commit changes" or "Send", or something else. This will cause the postback which gets the whole batch update process started. Either way, the only thing you want to do in the Update/Delete/Add row batch events is simply make changes to your dataset. You don't re-bind here.