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.
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.
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.
The object data source does delete rows on the client with the following java script which is found in Default.aspx:
function DeleteRow() { var row = igtbl_getActiveRow("UltraWebGrid1"); if (row != null) row.remove(); else alert("Please select a row");
}
That is all that is needed to remove a row on the client. You just need a reference to a row object and then you call the remove method on it. That will remove it from the grids rows collection on the client so when a postback is performed, DeleteRow or DeleteRowBatch will fire. To add a row on the client, you can use this syntax:
This will add a new row to the end of the grids rows collection. For batch updates, you can follow these knowledge base articles:
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=8270http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=8272