date conversion in gridview RRS feed

  • Question

  • User589052352 posted


    I want to display dates according to locale of user so that atleast UK / US formats work.

    Any suggestions in doing it ? I m trying to do in aspx file. I have like 10 webpages where I need to make this change. so looking for minimal changes.



    Wednesday, July 16, 2014 4:09 PM

All replies

  • User-760709272 posted
    string[] lang = Request.UserLanguages;
    string locale = string.Empty;
    if (lang.Length > 0)
        locale = lang[0];
        // you need a default as the browser might not send a language
        locale = "en-GB"; // UK
        // locale = "en-US"; // US
    CultureInfo c = new CultureInfo(locale);
    string d = DateTime.Now.ToString(c);
    string n = (1000000.11).ToString("C", c);

    if you don't want to have to update your ToString functions to accept the culture you can do this instead

    CultureInfo c = new CultureInfo(locale);
    Session.LCID = c.LCID;
    string d = DateTime.Now.ToString();
    string n = (1000000.11).ToString("C");

    Wednesday, July 16, 2014 6:27 PM
  • User589052352 posted

    How do I put that  sample code in

                                <ControlStyle Font-Names="Verdana" Font-Size="9pt"></ControlStyle>
                                    <asp:TextBox ID="TextBox12" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"bDate","{0:d}") %>'


    Wednesday, July 16, 2014 6:56 PM
  • User-760709272 posted

    I haven't tried this but try putting the Session.LCID version in the Page_Load event in the code behind.

    Wednesday, July 16, 2014 7:34 PM