Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. DateTime formats in GridView based on Cultural settings

DateTime formats in GridView based on Cultural settings

Scheduled Pinned Locked Moved ASP.NET
helptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shivan Nandan
    wrote on last edited by
    #1

    Hello friends, I set the cultural info for Germany as CultureInfo ci = new CultureInfo("de-DE"); // format is dd.MM.yyyy Then I bound the GridView, but the date field shows data in system's local date format( eg m/d/yyyy). How to get the date field to be displayed according to the cultural format Please help me Regards

    Shivanandan C V

    C N 2 Replies Last reply
    0
    • S Shivan Nandan

      Hello friends, I set the cultural info for Germany as CultureInfo ci = new CultureInfo("de-DE"); // format is dd.MM.yyyy Then I bound the GridView, but the date field shows data in system's local date format( eg m/d/yyyy). How to get the date field to be displayed according to the cultural format Please help me Regards

      Shivanandan C V

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I suspect you'd have to either ask the client their locale, get a database to map IP addresses to locales, or do something in javascript. Most sites ask the user where they are and store that info.

      Christian Graus Driven to the arms of OSX by Vista.

      1 Reply Last reply
      0
      • S Shivan Nandan

        Hello friends, I set the cultural info for Germany as CultureInfo ci = new CultureInfo("de-DE"); // format is dd.MM.yyyy Then I bound the GridView, but the date field shows data in system's local date format( eg m/d/yyyy). How to get the date field to be displayed according to the cultural format Please help me Regards

        Shivanandan C V

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Shivan Nandan wrote:

        How to get the date field to be displayed according to the cultural format

        CultureInfo ci = new CultureInfo("de-DE");
        DateTime.Now.ToString(ci.DateTimeFormat.ShortDatePattern, ci.DateTimeFormat)

        But this will not help you as you are using ASP.NET. This will use servers culture information. As Christian told, you need to have some mechanism to get the users culture. Most easy way is to ask them to provide it.

        Navaneeth How to use google | Ask smart questions

        S 1 Reply Last reply
        0
        • N N a v a n e e t h

          Shivan Nandan wrote:

          How to get the date field to be displayed according to the cultural format

          CultureInfo ci = new CultureInfo("de-DE");
          DateTime.Now.ToString(ci.DateTimeFormat.ShortDatePattern, ci.DateTimeFormat)

          But this will not help you as you are using ASP.NET. This will use servers culture information. As Christian told, you need to have some mechanism to get the users culture. Most easy way is to ask them to provide it.

          Navaneeth How to use google | Ask smart questions

          S Offline
          S Offline
          Shivan Nandan
          wrote on last edited by
          #4

          Dear friend, Thanks for your response. I am not using dt.tostring() method. My code is given below DataSet ds = new DataSet(); ds = obj.GetData(); gvList.DataSource = ds; gvList.DataBind(); The "ds" contains records and one of the field will be a datetime type. So I want that datetime field value to be displayed according to the cultural settings. Also gvList's Autogenerate colums is true.

          Shivanandan C V

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups