title: Problems with Formview showing details of Gridview selected row
body: <p>I am trying to have a user select a row in this grid view and have a set of details about that entry display in a formview. Currently, I am getting the error "Invalid column name 's.SprayId' ". I have encountered several issues with this and am out of ideas. I have posted my code below. Any ideas on how to fix this or a better way to do it? Thanks. </p>
  
  <pre><code>&lt;asp:GridView ID="gvHistory" runat="server" DataSourceID="dsHistory" AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" DataKeyNames="SprayId"&gt;
      &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775"&gt;&lt;/AlternatingRowStyle&gt;
      &lt;Columns&gt;
          &lt;asp:CommandField ShowSelectButton="True"&gt;&lt;/asp:CommandField&gt;
      &lt;/Columns&gt;
      &lt;EditRowStyle BackColor="#999999"&gt;&lt;/EditRowStyle&gt;
  
      &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"&gt;&lt;/FooterStyle&gt;
  
      &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"&gt;&lt;/HeaderStyle&gt;
  
      &lt;PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="White"&gt;&lt;/PagerStyle&gt;
  
      &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333"&gt;&lt;/RowStyle&gt;
  
      &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"&gt;&lt;/SelectedRowStyle&gt;
  
      &lt;SortedAscendingCellStyle BackColor="#E9E7E2"&gt;&lt;/SortedAscendingCellStyle&gt;
  
      &lt;SortedAscendingHeaderStyle BackColor="#506C8C"&gt;&lt;/SortedAscendingHeaderStyle&gt;
  
      &lt;SortedDescendingCellStyle BackColor="#FFFDF8"&gt;&lt;/SortedDescendingCellStyle&gt;
  
      &lt;SortedDescendingHeaderStyle BackColor="#6F8DAE"&gt;&lt;/SortedDescendingHeaderStyle&gt;
  &lt;/asp:GridView&gt;
  &lt;asp:SqlDataSource ID="dsHistory" runat="server" ConnectionString='&lt;%$ ConnectionStrings:WSFConnectionString %&gt;' SelectCommand="SELECT [SprayId], [Date], [TimeStart] FROM [Spray] WHERE ([Date] &gt;= (GETDATE() - 7)) ORDER BY [Date] DESC, [TimeStart] DESC"&gt;&lt;/asp:SqlDataSource&gt;
  &lt;asp:FormView ID="fvHistoryDetail" runat="server" CellPadding="4" ForeColor="#333333" DataSourceID="dsHistoryDetail" DataKeyNames="SprayId"&gt;
      &lt;EditItemTemplate&gt;
          SprayId:
          &lt;asp:Label Text='&lt;%# Eval("SprayId") %&gt;' runat="server" ID="SprayIdLabel1" /&gt;&lt;br /&gt;
          &lt;asp:LinkButton runat="server" Text="Update" CommandName="Update" ID="UpdateButton" CausesValidation="True" /&gt;&amp;nbsp;&lt;asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="UpdateCancelButton" CausesValidation="False" /&gt;
      &lt;/EditItemTemplate&gt;
  
      &lt;EditRowStyle BackColor="#999999"&gt;&lt;/EditRowStyle&gt;
  
      &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"&gt;&lt;/FooterStyle&gt;
  
      &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"&gt;&lt;/HeaderStyle&gt;
  
      &lt;InsertItemTemplate&gt;
          &lt;asp:LinkButton runat="server" Text="Insert" CommandName="Insert" ID="InsertButton" CausesValidation="True" /&gt;&amp;nbsp;&lt;asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="InsertCancelButton" CausesValidation="False" /&gt;
      &lt;/InsertItemTemplate&gt;
      &lt;ItemTemplate&gt;
          SprayId:
          &lt;asp:Label Text='&lt;%# Eval("SprayId") %&gt;' runat="server" ID="SprayIdLabel" /&gt;&lt;br /&gt;
  
      &lt;/ItemTemplate&gt;
  
      &lt;PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="White"&gt;&lt;/PagerStyle&gt;
  
      &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333"&gt;&lt;/RowStyle&gt;
  &lt;/asp:FormView&gt;
  &lt;asp:SqlDataSource ID="dsHistoryDetail" runat="server" ConnectionString='&lt;%$ ConnectionStrings:WSFConnectionString %&gt;' SelectCommand="SELECT s.SprayId as 'ID', [Date], TimeStart as 'Time Start', StartLocationDescription as 'Start', EndLocationDescription as 'End', v.VehicleNumber, (a.FirstName + a.LastName) as 'Applicator', c.TradeName as 'Chemical' FROM Spray s join Vehicle v on s.VehicleId = v.VehicleId join Applicator a on s.Applicator1Id = a.ApplicatorId join SprayChemicalsUsed scu on scu.SprayId = s.SprayId join ChemicalsUsed cu on scu.ChemUsedId = cu.ChemUsedId join Chemical c on cu.ChemId = c.ChemId WHERE ([s.SprayId] = @SprayId)"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:ControlParameter ControlID="gvHistory" PropertyName="SelectedValue" DefaultValue="1" Name="SprayId" Type="Int32"&gt;&lt;/asp:ControlParameter&gt;
      &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  </code></pre>