ASP.Net 2 Two Way Binding and DateTime Format Problem

Discussion in 'ASP .Net Web Controls' started by Ludovic DE FREITAS, Jan 9, 2006.

  1. Hello,

    I have a ASP.Net page where I use the new two-way binding.
    Unfortunatly the Update have problem with DateTime format.

    I use a TextBox : <asp:TextBox runat="server" id="tbDate" Text='<%#
    Bind("MyDate","{0:dd/MM/yyyy}") %>

    The Binding (display) works, but the Update use another format "MM/dd/yyyy".
    I have try to change the Thread Culture, the browser culture, the server
    regional settings and nothing works.
    I have check the UpdateItem with Reflector in FormView class, ans It seems
    that the InvariantCulture is used to convert string to DateTime !!!

    Can anyone help me with this problem ?

    Thanks.
     
    Ludovic DE FREITAS, Jan 9, 2006
    #1
    1. Advertising

  2. The solution lies in using the UpdateParameters collection to cast the
    TextBox's date string format to an internal DateTime type.

    If I build a web page that allows the user’s browser to determine the
    display of the date, yet my database operates on a server using the culture
    setting for en-us, then I would get an error that "Cannot convert value of
    parameter 'OrderDate' from 'System.String' to 'System.DateTime' ":
    http://www.webswapp.com/CodeSamples/aspnet20/GridView_2c_error.aspx

    If I add an UpdateParameters section within my objectDataSource defintion to
    explicitly cast the edited values to their appropriate date type, I do not
    get that error as in this demo:
    http://www.webswapp.com/CodeSamples/aspnet20/GridView_2c.aspx

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Ludovic DE FREITAS" wrote:

    > Hello,
    >
    > I have a ASP.Net page where I use the new two-way binding.
    > Unfortunatly the Update have problem with DateTime format.
    >
    > I use a TextBox : <asp:TextBox runat="server" id="tbDate" Text='<%#
    > Bind("MyDate","{0:dd/MM/yyyy}") %>
    >
    > The Binding (display) works, but the Update use another format "MM/dd/yyyy".
    > I have try to change the Thread Culture, the browser culture, the server
    > regional settings and nothing works.
    > I have check the UpdateItem with Reflector in FormView class, ans It seems
    > that the InvariantCulture is used to convert string to DateTime !!!
    >
    > Can anyone help me with this problem ?
    >
    > Thanks.
     
    Phillip Williams, Jan 9, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    771
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    606
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    447
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    380
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    806
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page