I have a WebDataGrid and am able to add a row if I insert the data and tab off or hit the enter key, but I have a save button outside of the grid that the users are used to pressing after they have updated existing records and I want them to be able to press this button when they have inserted new data to add a new row. Any suggestions?
Hi, Algunderson.
You don't need anything except enabling the Batch Updating in the grid and "Save" button making postback to the server. You can follow the topics for the feature and especially Enabling Batch Updating.
In case you want to achieve this with 11.1, without Batch Updating feature, you can use the approach that AgentD5 suggested you - using _commit() method. But don't forget in this case to cancel the automatic postback, as I suggested you in the previous post, using EditingClientEvents-RowAdding client-side event.
I hope you will be able to resolve your issue.
Best regards, Nikolay
OK...I was still on 2011.1 earlier. I'm in the process of changing all the classic ASP controls in my app to ASP.net controls and was trying to hold off on upgrading the app to 2012.1. Since the BatchUpdating wasn't available with the 2011.1 version, I went ahead and upgraded to 2012.1. I enabled BatchUpdating and tested adding a record on the new row and pressing my save button, but it doesn't seem to add the record. Do I need to do anything other than enable BatchUpdating to be able to save the record simply by pressing the submit button?
Hi again, Algunderson.
This is happening because you don't have BatchUpdating behavior enabled. In this way when you finish editing the new row it will automatically make a postback to the server and will save the row data. And after you click "Save" the data will be saved again.
Again I will suggest you to use Batch Updating without even calling _commit() method, because with Batch Updating, to save the data into the data source you only need to have one button that will make simple postback to the server. The grid will handle this internally. It will be good for you because you have only one "Save" button for the whole grid. So to change your code just enable Batch Updating of the WebDataGrid and set the WebImageButton property AutoSubmit to true, if not set by default.
The other option is to attach to the EditingClientEvents-RowAdding client-side event of the WebDataGrid and cancel it. Then the automatic postback will not happen and by clicking "Save" button you will have only one row added. All this is if you don't have BatchUpdating enabled.
<ig:EditingCore EditingClientEvents-RowAdding="cancelRowAdding">
In JavaScript, define the handler:
function cancelRowAdding(sender, e){
e.set_cancel(true);
}
There is third possible way if you like it - using Row Editing Template.
I made the change you suggested (<%=grid.ClientID%>)...but now it's working too well! It is actually saving the record twice now.I have one save button for the whole grid.
You can check if this isn't your problem. You need to call:
$find("<%=grid.ClientID%>") instead of $find("grid"), if your control isn't with static id.
As far as about the sample that I sent you, the row is added but it's in the end of the grid at the last page, that's why you cannot see it. Do you want to have seperate "Save" button for every row or one for the whole grid?
Thanks, Nikolay