Can anyone provide a summary or sample of how to accompilsh this? I am using the row edit templates for updating rows and this works fine but how can I duplicate this functionality for adding rows?
Hi,
The row edit template can be used to add new rows to the grid. The following lines of code shows how to do this:
this.UltraWebGrid1.DisplayLayout.AddNewBox.Hidden = false; this.UltraWebGrid1.DisplayLayout.AddNewRowDefault.Visible = AddNewRowVisible.No; this.UltraWebGrid1.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes; this.UltraWebGrid1.DisplayLayout.AllowUpdateDefault = AllowUpdate.RowTemplateOnly;
This way when the default empty row is not visible at the bottom of the Grid and it only appears when the AddNew button is clicked. When a cell in the new empty row is double clicked it opens up the Row Edit Template.
The only problem I am having is that I can't detemine which event to handle after the insert or why no data is being inserted.
The UltraWebGrid1_AfterRowInsertHandler fires when I hit the Add New Box button but should it be?? I think the grid fails on insert becaue the row is empty.
UltraWebGrid1_TemplateUpdateCellsHandler fires after clicking the Ok button on the row edit template. From within the UltraWebGrid1_TemplateUpdateCellsHandler event I issue a postback but nothing gets inserted into the database. And the sqldatasource1_inserted event is never fired.
If I remove the UltraWebGrid1_TemplateUpdateCellsHandler and use an imagebutton to cause postback the record still is NOT inserted.
Updates and Deletes work fine.
What am I missing?
In this case, I think we have to handle the event AfterRowTemplateCloseHandler on the client side and then call the UpdateRow event from the server. Here is how the AfterRowTemplateCloseHandler should look like:
function UltraWebGrid1_AfterRowTemplateCloseHandler(gridName, rowId, bSaveChanges)
{
}
The key here is the method processUpdateRow method on the UltraWebGrid row. This fires the UpdateRow event in the server and thus the DataSource gets updated. Even though you are inserting a new row, it should be handled with the UpdateRow event.
If you are using DataSet to update the database, then please visit the following link, which explains how to do it with step by step example.
http://help.infragistics.com/Help/NetAdvantage/NET/2008.3/CLR3.5/html/WebGrid_Updating_Data_with_a_Data_Set.html
I hope this helps.
Thanks
I am handling the update from the datasource not the manual method. These events both fire and the grid is updated but it is still not updating the database.
function UltraWebGrid1_AfterRowTemplateCloseHandler(gridName, rowId, bSaveChanges){ debugger;
try { var row = igtbl_getRowById(rowId); row.processUpdateRow(true); } catch ( err ) { var txtMessage = document.title + " - Error in UltraWebGrid1_AfterRowDeletedHandler()\n" + err.description ; alert( txtMessage ) ; }
function UltraWebGrid1_AfterRowUpdateHandler(gridName, rowId){ debugger;
try { var oGrid = igtbl_getGridById(gridName); igtbl_doPostBack(gridName); } catch ( err ) { var txtMessage = document.title + " - Error in UltraWebGrid1_AfterRowDeletedHandler()\n" + err.description ; alert( txtMessage ) ; }
Both of these events are client side events. The Server side UpdateRow event must be handled for this purpose. This event can be located from the provided list of events (not the client side events under DisplayLayout). Please open the Properties Window for ultraWebGrid and click on the events and navigate to this "UpdateRow" event and double click on it. It creates the signature in the code behind page. The signature in the should look as follows:
If the datasource is updating itself then you don't have to add any code here. To update the datasource we need to do a page postback and the processUpdateRow method from the client side causes this postback.
Hope this helps.
Thanks Sarita. You were very helpful.
It works now. Now I just have to move this to a user control and get it to work.