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.
If I understood you right, what you want to achieve is to add one or more rows to the grid and then by pressing Save button to send the new data to the server. If you want this you can check this sample.
By default when you add a row to the grid after the new row looses focus, it automatically makes a postback to the server and saves the new row data in the data source. If you want to update several rows at once, without an automatic postback, you need to enable BatchUpdating behavior of the grid. With this behavior enabled, when the new row looses focus, no automatic postback happens. The save of the new data into the data source happens when you make the first postback to the server. The sample above shows you exactly that. I hope this will help you and if you have other questions, don't hesitate to ask them.
Best regards, Nikolay
I looked at the sample, but it doesn't seem to do what I'm trying to accomplish. I was hoping that once I entered data into the "Add" row, I would be able to press the "Submit Data" button and the data would be saved to the grid...but it isn't. It seems to only save the newly added row if the tab or enter keys are pressed. Is there any way to get the new row added 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.
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?
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.
I have enabled batch updating and the save button does post back to the server, but the new record seems to only save if I hit the enter or tab key and then press the "Save Button". I would like for the user to be able to just type the data and press the "Save Button" and the data be saved. Am I missing something?
Hi, Algunerson.
You need also to enable adding a row, but I suppose you've already did it.
<ig:EditingCore BatchUpdating="true">
<Behaviors>
<ig:RowAdding>
</ig:RowAdding>
<ig:RowDeleting/>
<ig:CellEditing>
</ig:CellEditing>
</Behaviors>
</ig:EditingCore>
If you want to paste me the code that you are using and tell me which DLL version you are using and I will try to see where the problem is.
Thanks, Nikolay
Hi, Angela.
I don't know if I will be able to help you. I suppose the posts you've already red, have more information about this problem. The WebDataGrid can disable editing on a column, but I suppose this is not appropriate for your case. As far as for the next 12.2 there is not going to have cell editing feature for sure, and I don't know about future releases. But I think you can do a feature request about this functionality and it is possible to be implemented in the future, if the architecture of the control allows this. If this is common problem, I suppose that there is already such requests, and if you want to understand some information and progress on this you can create forum thread and the guys from Developer Support will take care to give you most recent information.
I know this is not the best place to ask this question, but you were so helpful with this problem...so I thought I would try here first.To my knowledge, there isn't an easy way to do the following while using the WebDataGrid: (This is how I set a cell to allow/not allow editing on a specific cell using the UltraWebGrid) Protected Sub grid_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.RowEventArgs) Handles grid.InitializeRow If Page.User.IsInRole("App_AIM_Admin_Users") Then e.Row.Cells.FromKey("DOS").AllowEditing = Infragistics.WebUI.UltraWebGrid.AllowEditing.Yes Else If e.Row.Cells.FromKey("Approved_Flag").Value = 1 Then 'checked e.Row.Cells.FromKey("DOS").AllowEditing = Infragistics.WebUI.UltraWebGrid.AllowEditing.No Else e.Row.Cells.FromKey("DOS").AllowEditing = Infragistics.WebUI.UltraWebGrid.AllowEditing.Yes End If End If End Sub
I have a workaround, but it seems confusing and I don't really want to go through the trouble of changing all of the pages in my application if this is a feature that will be added in the next WebDataGrid release. For the most part, I have been able to replicate how things worked with the UltraWebGrid in the WebDataGrid...but this is the one thing that I definately see as a big disappointment for the WebDataGrid. Do you know if there are plans to have this feature added to the WebDataGrid anytime soon? I have seen several posts where others have asked for it and have been surprised that it's not a current feature.If there is somewhere else I should post this question that would be more appropriate, please let me know and I will be happy to do so.
I was not able to get it to work for some reason. As a quick fix, I just added an "Add Record" button and kept the "Save" button, but renamed it "Save Changes". I used the code from one of your previous post to get it to work the way I wanted it to work. I got pulled off on another project, so I wasn't able to spend more time trying to determine why I wasn't able to get it to work. I will definately have to revisit this one to see if I can get it to work at some point.Thank you very much for all of your time and help. I really appreciate it.
Did my last post helped you to resolve your issue?
Best reagards, Nikolay
This problem has nothing common with editing. It' because every time you press the "Save" button, the Add Row is sent to the server, even if it's empty. It's because get_rowAdding() gets reference to the object that represents the new row template at the bottom of the grid and every time the row is added, even it is with no data. That's why you first need to check if there is a new cell values in the Add Row.
In most of the cases it's not recommended to use internal methods, like _commit(), because as you see it's possible that some problems may occur. But don't worry I've created a script that checks if the row is been updated and if yes, then it is added as a new row, when the "Save" button is pressed.
The following code defines an array of the default cell values for every column and just checks if the new cell value is different from the default one. Unfortunately I couldn't find grid method that do this, that's why I've created the code below that works for me. I hope it will resolve your issue.
<script type="text/javascript">
var toSave = false;
function cancelRowAdding(sender, e) {
if (!toSave) {
toSave = false;
function saveRow() {
var rowToAdd = $find("<%= wdg1.ClientID %>")
.get_behaviors().get_editingCore()
.get_behaviors().get_rowAdding();
toSave = true;
if (isRowToAddChanged(rowToAdd)) {
rowToAdd._commitRow();
function isRowToAddChanged(rowToAdd) {
var cellCount = rowToAdd.get_row().get_cellCount(),
cellInd = 0,
// you don't need that array if all your default cell values are null.
defaultRowValues = ["---", null, null, null, null, null, null];
for (cellInd; cellInd < cellCount; cellInd++) {
if (rowToAdd.get_row().get_cell(cellInd).get_value() !== defaultRowValues[cellInd]) {
return true;
// If all your default values are null then use the following code:
/*
if (rowToAdd.get_row().get_cell(cellInd).get_value() !== null) {
*/
</script>