Hi, I want to show datetime fields formated as {0:dd/MM/yy}, I set the DateFormatString value for Insert and Edit templates for my asp:DynamicControl and works OK, but when I edit the filed and press Update I get the exception: Could not find a row that
matches the given keys in the original values stored ViewSates....
It is not exactly the same situation but I get the same message when I press on Update on a row of a Gridview, no matter what type of field I modify:
“Could not find a row that matches the given keys in the original values stored in ViewState. Ensure that the 'keys' dictionary contains unique key values that correspond to a row returned from the previous
Select operation. “
It is not exactly the same situation but I get the same message when I press on Update on a row of a Gridview, no matter what type of field I modify:
“Could not find a row that matches the given keys in the original values stored in ViewState. Ensure that the 'keys' dictionary contains unique key values that correspond to a row returned from the previous
Select operation. “
You need to make sure that your table does the following:
1) Has a primary key.
2) In the Linq to SQL Designer you need to make sure the field on the table as marked as a primary key.
This error typically indicates that LinqDataSource was not able to lookup the right row to modify because there was not primary key information available. Let me know if this helps!
Hi, thanks, at least in my case the errors comes due to I made some changes in database and not all tabels was updates in linq to sql designer. I delete all tables and add again and now is ok.
Is it possible that your Linq model is out of sync with your database, or that the bound fields on your page our out of sync with your linq model? When that error happens for me that is usually what causes it.
Thanks,
Leonid
This posting is provided "AS IS" with no warranties, and confers no rights.
I'm having the exact same problem, but with a FormView. I've resynched the Linqs view and Datasource. I was having the problem wiht the Update as well as Insert. For the insert, the workaround was to make the field invisible and then set the InsertParameter
to Nullable (the field gets autopoluated)
alfhv
Member
1 Points
13 Posts
DateTime field format
Apr 13, 2008 03:51 PM|LINK
Hi, I want to show datetime fields formated as {0:dd/MM/yy}, I set the DateFormatString value for Insert and Edit templates for my asp:DynamicControl and works OK, but when I edit the filed and press Update I get the exception: Could not find a row that matches the given keys in the original values stored ViewSates....
What I'm doing wrong ?
Thanks
maira.wenzel
Member
511 Points
111 Posts
Microsoft
Re: DateTime field format
Apr 14, 2008 07:25 PM|LINK
Do you get this error message when you don't set the DateFormatString property?
Can you post the code that you're using for your custom page?
Thanks,
Maíra
DinuA
Member
20 Points
47 Posts
Update a row in a gridview [Re: DateTime field format]
Apr 14, 2008 08:09 PM|LINK
It is not exactly the same situation but I get the same message when I press on Update on a row of a Gridview, no matter what type of field I modify:
“Could not find a row that matches the given keys in the original values stored in ViewState. Ensure that the 'keys' dictionary contains unique key values that correspond to a row returned from the previous Select operation. “
Below the code of that page.Thank you very much.
1 <%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="ShowTowns.aspx.vb" Inherits="BSDMaint.ShowTowns"
2 title="Towns" %>
3 <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
4 <asp:Label ID="lblTitle" CssClass="HeaderStyle" runat="server" Text="(title)"></asp:Label>
5 <br />
6 <asp:Label ID="lblMessage" runat="server" ForeColor="#FF3300"></asp:Label>
7 <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
8 <asp:GridView ID="grvTown" runat="server" AllowSorting="True"
9 AutoGenerateColumns="False" CellPadding="4"
10 CssClass="label1" DataSourceID="TownLinqDataSource"
11 EnableSortingAndPagingCallbacks="True" Font-Size="Small" ForeColor="#333333"
12 GridLines="None" ShowFooter="True" Width="304px">
13 <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
14 <RowStyle BackColor="#EFF3FB" />
15 <Columns>
16 <asp:CommandField ShowEditButton="True" />
17 <asp:BoundField ApplyFormatInEditMode="True" DataField="TownName"
18 HeaderText="Town Name" SortExpression="TownName" />
19 <asp:BoundField DataField="CtryCode" HeaderText="Ctry"
20 SortExpression="CtryCode" />
21 <asp:BoundField DataField="TownELcode" HeaderText="ELcode"
22 SortExpression="TownELcode" />
23 <asp:BoundField DataField="TownNameVariants" HeaderText="Name Variants"
24 SortExpression="TownNameVariants" />
25 <asp:BoundField DataField="DateAdded" HeaderText="Date Added" ReadOnly="True"
26 SortExpression="DateAdded" />
27 <asp:BoundField DataField="DateModified" HeaderText="Date Modified"
28 SortExpression="DateModified" />
29 <asp:BoundField DataField="TownID" HeaderText="TownID" ReadOnly="True"
30 SortExpression="TownID" />
31 </Columns>
32 <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
33 <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
34 <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
35 <EditRowStyle BackColor="#2461BF" />
36 <AlternatingRowStyle BackColor="White" />
37 </asp:GridView>
38
39 <asp:LinqDataSource ID="TownLinqDataSource" runat="server"
40 ContextTypeName="BSDMaint.DataClassesDataContext" EnableDelete="True"
41 EnableUpdate="True" OrderBy="TownName" TableName="Towns">
42 </asp:LinqDataSource>
43
44 <br />
45 <br />
46 <br />
47
48 </asp:Content>
49
DinuA
Member
20 Points
47 Posts
Update a row in a gridview [Re: DateTime field format]
Apr 14, 2008 08:10 PM|LINK
It is not exactly the same situation but I get the same message when I press on Update on a row of a Gridview, no matter what type of field I modify:
“Could not find a row that matches the given keys in the original values stored in ViewState. Ensure that the 'keys' dictionary contains unique key values that correspond to a row returned from the previous Select operation. “
Below the code of that page.Thank you very much.
1 <%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="ShowTowns.aspx.vb" Inherits="BSDMaint.ShowTowns"
2 title="Towns" %>
3 <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
4 <asp:Label ID="lblTitle" CssClass="HeaderStyle" runat="server" Text="(title)"></asp:Label>
5 <br />
6 <asp:Label ID="lblMessage" runat="server" ForeColor="#FF3300"></asp:Label>
7 <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
8 <asp:GridView ID="grvTown" runat="server" AllowSorting="True"
9 AutoGenerateColumns="False" CellPadding="4"
10 CssClass="label1" DataSourceID="TownLinqDataSource"
11 EnableSortingAndPagingCallbacks="True" Font-Size="Small" ForeColor="#333333"
12 GridLines="None" ShowFooter="True" Width="304px">
13 <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
14 <RowStyle BackColor="#EFF3FB" />
15 <Columns>
16 <asp:CommandField ShowEditButton="True" />
17 <asp:BoundField ApplyFormatInEditMode="True" DataField="TownName"
18 HeaderText="Town Name" SortExpression="TownName" />
19 <asp:BoundField DataField="CtryCode" HeaderText="Ctry"
20 SortExpression="CtryCode" />
21 <asp:BoundField DataField="TownELcode" HeaderText="ELcode"
22 SortExpression="TownELcode" />
23 <asp:BoundField DataField="TownNameVariants" HeaderText="Name Variants"
24 SortExpression="TownNameVariants" />
25 <asp:BoundField DataField="DateAdded" HeaderText="Date Added" ReadOnly="True"
26 SortExpression="DateAdded" />
27 <asp:BoundField DataField="DateModified" HeaderText="Date Modified"
28 SortExpression="DateModified" />
29 <asp:BoundField DataField="TownID" HeaderText="TownID" ReadOnly="True"
30 SortExpression="TownID" />
31 </Columns>
32 <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
33 <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
34 <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
35 <EditRowStyle BackColor="#2461BF" />
36 <AlternatingRowStyle BackColor="White" />
37 </asp:GridView>
38
39 <asp:LinqDataSource ID="TownLinqDataSource" runat="server"
40 ContextTypeName="BSDMaint.DataClassesDataContext" EnableDelete="True"
41 EnableUpdate="True" OrderBy="TownName" TableName="Towns">
42 </asp:LinqDataSource>
43
44 <br />
45 <br />
46 <br />
47
48 </asp:Content>
49
maira.wenzel
Member
511 Points
111 Posts
Microsoft
Re: Update a row in a gridview [Re: DateTime field format]
Apr 14, 2008 08:48 PM|LINK
Could you do a test and set the EnablePartialRendering property to "false" in your site.master and see if doing this resolves the issue?
It seems that AJAX UpdatePanel control has a problem with pages with a large view state.
Thanks,
Maíra
scothu
Participant
1436 Points
291 Posts
Microsoft
Moderator
Re: Update a row in a gridview [Re: DateTime field format]
Apr 14, 2008 10:27 PM|LINK
You need to make sure that your table does the following:
1) Has a primary key.
2) In the Linq to SQL Designer you need to make sure the field on the table as marked as a primary key.
This error typically indicates that LinqDataSource was not able to lookup the right row to modify because there was not primary key information available. Let me know if this helps!
...Scott
PM, ASP.NET Team, Microsoft
alfhv
Member
1 Points
13 Posts
Re: Update a row in a gridview [Re: DateTime field format]
Apr 14, 2008 10:39 PM|LINK
Hi, thanks, at least in my case the errors comes due to I made some changes in database and not all tabels was updates in linq to sql designer. I delete all tables and add again and now is ok.
thanks.
DinuA
Member
20 Points
47 Posts
Re: Update a row in a gridview [Re: DateTime field format]
Apr 15, 2008 07:08 AM|LINK
Thank you Scott.
The answer is YES to both questions. The primary key is present in the gridview row.
Leonid Tsybe...
Participant
1145 Points
226 Posts
Microsoft
Re: Update a row in a gridview [Re: DateTime field format]
Apr 15, 2008 05:03 PM|LINK
Is it possible that your Linq model is out of sync with your database, or that the bound fields on your page our out of sync with your linq model? When that error happens for me that is usually what causes it.
Leonid
This posting is provided "AS IS" with no warranties, and confers no rights.
mfitzwad
Member
2 Points
1 Post
Re: Update a row in a gridview [Re: DateTime field format]
Apr 17, 2008 05:04 PM|LINK
I'm having the exact same problem, but with a FormView. I've resynched the Linqs view and Datasource. I was having the problem wiht the Update as well as Insert. For the insert, the workaround was to make the field invisible and then set the InsertParameter to Nullable (the field gets autopoluated)
<InsertParameters>
<asp:Parameter Name="PrimaryID" Type="Int32" ConvertEmptyStringToNull="true"/>
</InsertParameters>
But I'm still getting this error with UPDATES.
Anything?
Thanks so much for your time.
-Michael
---
http://www.radiantdays.com