in ASP.NET 19.2 I have a webdatagrid with a sql datasource. Set behaviors to allow an "add row".
I see the addrow and I type in the info for the new record:
However, I can't seem to get the grid to add this record or update the datasource. Tried clicking another record to make the addrow lose focus, and also tried to move a column to force a postback, but nothing seems to work. What am I missing?
Hello,
Thank you for posting in our community.
To add the row you have to use Tab or Enter key. To add row when the focus is lost, the Activation behavior has to be enabled and the selection one disabled. If the selection is needed then the client-side event ExitedEditMode on the rowAdding behavior can be handled as follows:
<ig:RowAdding> <AddNewRowClientEvents ExitedEditMode="WebDataGrid1_RowAdding_ExitingEditMode" /> </ig:RowAdding>
function WebDataGrid1_RowAdding_ExitingEditMode(sender, eventArgs) { var rowAdding = sender.get_behaviors().get_editingCore().get_behaviors().getBehaviorByName("RowAdding"); rowAdding._commitRow(); }
Please let me know if you need any further assistance with this matter.
Hi Martin, I am seeing strange behavior. I turned off "selection" and made sure "activation" was on.
I entered info into the AddRow and then clicked another cell in a different row. Got this error:
Which is strange since I filled in the "UserID" cell. So I rebuilt the datasource commands to make sure they were correct:
As you can see the insert (and update) stmt seem to be fine. I then tried to simply edit a cell. After changing the value of a cell I got some sort of confirmation popup (I don't know why I got it or where it came from).
So I clicked "done" but as soon as the cell lost focus, the original value returned.
Is there a pdf manual available that fully documents the webdatagrid? I have not been able to find one. I've only found a series of web pages documenting individual features. I would be looking for an "all in one" pdf file.
Any ideas on what I might be doing wrong? This project is a revival of an old project which used the old version of the asp grid, and it worked fine. This new webdatagrid does not seem to be as simple as the old one.
Thanks for your help.
Hi Ron,
Indeed we have such a manual. It can be found here.
If you have more than one column which does not allow NULL values in your data base, the error like in your second screenshot would appear. My suggestion is to handle the client-side event RowAdding to check if an empty cell for a column which does not allow NULL values exists. If there is, you can cancel the event:
....... <ig:EditingCore> <EditingClientEvents RowAdding="checkForEmptyCell" /> ......
function checkForEmptyCell(sender, event) { var firstName = event.get_row().get_cellByColumnKey("FirstName").get_value(); var lastName = event.get_row().get_cellByColumnKey("LastName").get_value(); if (!firstName || !lastName) event.set_cancel(true); }
The dialog I shown because the RowEditing behavior is enabled. To hide it you have to set the property EnableDialog of the behavior to False:
<ig:RowEditing EnableDialog="False"> </ig:RowEditing>
After you have edited the row, the value should change. I have created and attached a sample for your reference. Let me know if it helps you to achieve your requirements.
3755.Sample.zip
After much investigation I found that I had both added columns to the grid manually, and I had the checkbox to add all fields automatically. This created a grid with all columns listed twice. I never scrolled the grid to the right so I never realized that the fields were listed twice. When I finally noticed this I realized the "null" field was from the second occurrence of the key field (which was never filled in). After removing the extra columns it seems to work. I want to thank you for all your help in this. I have used infragistics for windows forms for many years and the asp.net is a little bit of a learning curve.
One more thing... Although I did get records to add by hitting the ENTER key, I would like to have the new row added when the row loses focus. So I entered the code you specified in your first response
I did notice the you specify "exitingEditMode" in the "ExitedEditMode" ClientEvent. Was that a mistake? Anyway, when I put in your code, entered data into the AddRow, then clicked to another row, the addrow was not added. Is there anything else I need to do?