DateTime field format

Last post 06-13-2008 2:37 AM by Nilla. 13 replies.

Sort Posts:

  • DateTime field format

    04-13-2008, 11:51 AM
    • Loading...
    • alfhv
    • Joined on 04-13-2008, 12:18 AM
    • Posts 13

    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

  • Re: DateTime field format

    04-14-2008, 3:25 PM

    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

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Update a row in a gridview [Re: DateTime field format]

    04-14-2008, 4:09 PM
    • Loading...
    • DinuA
    • Joined on 06-09-2007, 4:43 PM
    • Posts 26

    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  

     
  • Update a row in a gridview [Re: DateTime field format]

    04-14-2008, 4:10 PM
    • Loading...
    • DinuA
    • Joined on 06-09-2007, 4:43 PM
    • Posts 26

    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  

     
  • Re: Update a row in a gridview [Re: DateTime field format]

    04-14-2008, 4:48 PM

    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

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Update a row in a gridview [Re: DateTime field format]

    04-14-2008, 6:27 PM
    • Loading...
    • scothu
    • Joined on 12-10-2007, 1:54 AM
    • Redmond, WA
    • Posts 109
    • AspNetTeam

    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

    Scott Hunter
    ASP.NET
  • Re: Update a row in a gridview [Re: DateTime field format]

    04-14-2008, 6:39 PM
    • Loading...
    • alfhv
    • Joined on 04-13-2008, 12:18 AM
    • Posts 13

    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.

  • Re: Update a row in a gridview [Re: DateTime field format]

    04-15-2008, 3:08 AM
    • Loading...
    • DinuA
    • Joined on 06-09-2007, 4:43 PM
    • Posts 26

    Thank you Scott.

    The answer is YES to both questions.  The primary key is present in the gridview row.

  • Re: Update a row in a gridview [Re: DateTime field format]

    04-15-2008, 1:03 PM

    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.
  • Re: Update a row in a gridview [Re: DateTime field format]

    04-17-2008, 1:04 PM
    • Loading...
    • mfitzwad
    • Joined on 04-17-2008, 4:08 PM
    • Posts 1

    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 

     

  • Re: Update a row in a gridview [Re: DateTime field format]

    04-20-2008, 2:35 PM

    Same problem here. I have a custom query in OnSelecting but other than that everything is quite standard. I tried turning off EnablePartialRendering, checking to see that the table has a primary key, and remaking the LINQ dbml. Here's the relevant code: 

    var v = from c in Util.DC.Customers
            where !c.IsDeleted && c.Id == id
            select c;
     
    <asp:LinqDataSource ID="LinqDataSource1" runat="server"
        ContextTypeName="DataContext" TableName="Customers" 
        EnableUpdate="true" onselecting="LinqDataSource1_Selecting">
    </asp:LinqDataSource>
     
  • Re: Update a row in a gridview [Re: DateTime field format]

    05-13-2008, 7:07 PM
    Answer
    • Loading...
    • aldion
    • Joined on 10-11-2007, 3:46 PM
    • Redmond, WA
    • Posts 23
    • AspNetTeam

    "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. “

    make sure that the DataKeyNames property is set on the Gridview, specifying the primary key[s] of your table. 
    in the original posted code looks like the problem is a missing DataKeyNames="TownELcode" in the GridView definition, .

     

    hope it fixes it,
    Alexandre

  • Re: Update a row in a gridview [Re: DateTime field format]

    05-14-2008, 12:55 PM
    • Loading...
    • DinuA
    • Joined on 06-09-2007, 4:43 PM
    • Posts 26

    Yes Alex, problem fixed.

    Thank you very much.

    Dinu

  • Re: Update a row in a gridview [Re: DateTime field format]

    06-13-2008, 2:37 AM