Monday, March 24, 2008

ASP.NET 2.0 Gridview/Dataview Update does not work

Problems with my GridView/Dataview update, it doesn't update the record in the database, it doesn't generate an error either, it just reloads the page with the previous values.


Check 1:

If you select the GridView in the designer, and select that entry in the Properties box, you can select the correct values.The result should change your source line to look something like the following (in bold):

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1">


Check 2:

If you have NULL fields in your data and checked the "Use Optimistic Concurrency" option when configuring your SqlDatasource, then the update won't work. Re-configure the SqlDataSource (use the wizard again) and uncheck the "Use Optimistic Concurrency" option. It should work fine afterwards.