Hi there,
when the user adds a new row in a webdatagrid. Is there a way to access the newly added row cells from code behind so I can do an insert using my custom methods in code behind.
The reason for this is that I am not using automatic insertion, but the user wants to insert data only after he clicks on a save button.
So my question pls:
1/ how can I access the newly added row from code behind, and should I do something specific on the client side inorder to have this new row available ?
Because, when I iterate through my grid in code behind, I can NOT find the new row (the row count remains the same as the original row count during the binding) !!!
2/ do u think there is any better way to achieve the user's requirement ?
thanks a lot :)
Hi rtutus,
It sounds like what you want is actually batch updating. You would want the row to appear on the client BEFORE it is actually added to the data source? Currently that is not possible. With the row adding behavior or using grid.get_rows().add(arrayOfVals) on the client automatically have the grid make a postback (ajax or full depending upon EnableAjax property). Then we will add the row to the data source if AutoCRUD is on. If it is off, you should be handling the RowAdding server event and manually insert the new record. You don't see the row because only rows that exist in the data source are actually in that collection.
However, for 11.2 BatchUpdating will be available for the WebDataGrid. It will work for adding, deleting, and editing of cells. In the meantime, an option might be to use client rendering to fake this. You could handle row adding client event and cancel it. Then you would have to add the data to the client data source of the grid and rebind. You'd also have to log that delete action somewhere so that when the postback happens via the save button, you could perform all of the deletes.
regards,David Young
Hi,
"It sounds like what you want is actually batch updating. You would want the row to appear on the client BEFORE it is actually added to the data source?"
I don t necessarily need it to appear in the main grid rows list, it can remain in the "New Row" section of the grid since all I need to add is one row at a time. All I want is access the newly added row's cells from the code behind, after the user clicks a Save button, sorry I m misunderstanding, is that not possible using 10.2 ?
Anyway, The way i worked things around, I used AddNewRowClientEvents-ExitedEditMode client event, then stored the new rows'cells in hidden fields using this:
noteField.value = evntArgs.getCell().get_text();
Not very efficient way :( :(
Thank u Dave
The values in the add row are not carried back to the server if the row is just there. It only happens if the add row commits itself (like by pressing enter while in edit mode on the add row). Then this causes a postback. This would fire the RowAdding event. Off of those event args, you would have access to the values from the add row. So, what you could do is have a client side click handler for your save button that calls the row adding behavior commit row method;
var grid = $find("WebDataGrid1");
grid.get_behaviors().get_editingCore().get_behaviors().get_rowAdding()._commitRow();
And be sure to have AutoCRUD false on the editing core and handle rowAdding server event.
-Dave
oh cool, may be what I was missing is the following:
I ll try that out, I was calling just the commit of regular editing behaviour.
Thanks a lot :)