So I’m been pounding on this problem all day. I’ve got a LinqDataSource that points to my model and a GridView that consumes it. When I attempt to do an update on the GridView, it does not update the underlying data source. I thought it might have to do with the LinqDataSource, so I added a SqlDataSource and the same thing happens. The aspx is as follows (the code-behind page is empty):
<asp:SqlDataSource ID='SqlDataSource1' runat='server' ConnectionString='Data Source=devsql32;Initial Catalog=Steam;Persist Security Info=True;' ProviderName='System.Data.SqlClient' SelectCommand='SELECT [LangID], [Code], [Name] FROM [Languages]' UpdateCommand='UPDATE [Languages] SET [Code]=@Code WHERE [LangID]=@LangId'> </asp:SqlDataSource> <asp:GridView ID='_languageGridView' runat='server' AllowPaging='True' AllowSorting='True' AutoGenerateColumns='False' DataKeyNames='LangId' DataSourceID='SqlDataSource1'> <Columns> <asp:CommandField ShowDeleteButton='True' ShowEditButton='True' /> <asp:BoundField DataField='LangId' HeaderText='Id' ReadOnly='True' /> <asp:BoundField DataField='Code' HeaderText='Code' /> <asp:BoundField DataField='Name' HeaderText='Name' /> </Columns> </asp:GridView> <asp:LinqDataSource ID='_languageDataSource' ContextTypeName='GeneseeSurvey.SteamDatabaseDataContext' runat='server' TableName='Languages' EnableInsert='True' EnableUpdate='true' EnableDelete='true'> </asp:LinqDataSource>
What in the world am I missing here? This problem is driving me insane.
It turns out that we had a DataBind() call in the Page_Load of the master page of the aspx file that was probably causing the state of the GridView to get tossed out on every page load.
As a note – update parameters for a LINQ query are not required unless you want to set them some non-null default.