Hello ,I looked through all the the documentation and help and cannot find a sample on how to update my webgrid automatically with sqldatasource.On your sample page it shows: "With ASP.NET 2.0 DataSource Controls such as the SqlDataSourceControl, the WebGrid can provide automatic updating - no code required". but there is no sample anywhere of that.I have seen in the documentation updateDBrow but no sample was found for that.So please let me know how to use webgrid and the sqldatasource to automatically update my grid.ThanksARno
I know that this is an old (and probably stale) post, but I came across it in troubleshooting a similar situation and figured that there might be others out there that might benefit.
Other thing that you might want to check with update failures is the optimistic concurrency option on your update query. I had a similar problem and it all boiled down to a boolean column that had some null values in it. It appears that, when the SQL UPDATE statement is validating each column against the original value (WHERE FieldName = @original_FieldName) it was sending a value of 0 (false) for fields that were null when retrieved by the original SELECT statement. Since null and 0 aren't exactly interchangable, the update query was failing. I went into the underlying SQL table and updated all of the records that had a null value in that field to false and the updates began working fine. Other option would be to exclude the concurrency statement and just automatically overwrite the existing record, but that would depend entirely upon your particular situation (I'm not personally that brave or confident in my coding, particularly during the testing phases!).
I haven't verified whether it does the same thing with other numeric data types but I would think that the results could be similar...
If you were to post your code, somebody might spot the problem. You should include both markup and code-behind.
Hello, I have the same problem and I did everythig you said and nothing worked. What could it be? I'm using 2008 Vol1, could that be the problem?
Thanks
It should "just work" but in my experience I always forget to do the following (and get yelled at when I write it up as a bug).
Set the
grid.DataKeyField = primarykeycolumn
and optionally set
grid.Bands[0].BaseTableName=table
Also, when you create your SqlDataSource be sure to click on Advanced and choose to generate insert update and delete queries. That should be all there is to it.
Now, to get the update to happen you can either postback the entire page, or add an empty UpdateRow event handler (with grid's ajax enabled) and the data will be updated each time the user leaves a row.
Hope this helps,
-Tony