Sample
<asp:GridView ID="data_basic_addresses" runat="server" AllowPaging="False" BorderWidth="0" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="AddressId" HorizontalAlign="Center"
DataSourceID="LinqAddressDS" PageSize="20" CssClass="GridViewClass">
<Columns>
<asp:BoundField DataField="AddressId" HeaderText="AddressId" SortExpression="AddressId" ReadOnly="True"/>
<asp:BoundField DataField="Address" HeaderText="Street" SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="Zip" HeaderText="Zip" SortExpression="Zip" />
<asp:CommandField HeaderText="Options" ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqAddressDS" runat="server" OnContextCreating="LinqDS_ContextCreating" Where="AcctNo == @AcctNo"
ContextTypeName="MyProject.Models.DB_DataDataContext" EnableDelete="True" EnableInsert="True"
EnableUpdate="True" TableName="Tbl_Addresses" OrderBy="AddressId">
<WhereParameters>
<asp:QueryStringParameter DefaultValue="1" Name="AcctNo" QueryStringField="AcctNo" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
I set the WhereParamater value in the page_load method
Every time the update link is pressed after data is changed I receive an error stating “A critical error has occurred. Exception has been thrown by the target of an invocation.” or “Cannot access a disposed object”
When the grid view is reload fresh, the data is updated. Nothing I do seems to make a difference. Does anyone have any ideas on why?
Thanks in advance!
Found a fix for the problem
I was trying to pass my own instance of the model connection to be used in a
LinqDS_ContextCreatingmethod. This worked for all functionality except the Update command. I went in and updated the models default connection string in themodel.designer.csfile and now the update works.