views:

1286

answers:

4

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.

A: 

This is a total shot in the dark since I haven't used ASP at all.

I've been just learning XAML and WPF, which appears to be very similar to what you've posted above and I know that for some UI controls you need to specify the binding mode to two-way in order to get updates in both directions.

17 of 26
+2  A: 

You are missing the <UpdateParameters> sections of your DataSources.

LinqDataSource.UpdateParameters

SqlDataSource.UpdateParameters

Forgotten Semicolon
A: 

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.

John Christensen
A: 

Thanks John, exact same solution i needed for multi hour problem. I put a databind into page load for testing. Forgot to remove it, paranoia levels exponetiated.

Anthony Lawrence