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. Issues with sorting a dynamically created Gridview

Issues with sorting a dynamically created Gridview

Scheduled Pinned Locked Moved ASP.NET
databasealgorithmshelpquestion
4 Posts 2 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.
  • A Offline
    A Offline
    AaronM_NZ
    wrote on last edited by
    #1

    I am working on a project and I am a bit stumped with sorting of a Gridview. I am creating a DataTable, and one of the columns is populated with decimal numbers ranging from -100.00 to +100.00. I then DataBind the DataTable to the GridView, and then sort on the column. The problem is its sorting it as text, not as decimal numbers - so its sorted something like this: 9.33, -7.6, 3.3, 2.02, 14.6, -1.8, -1, 0.99, etc which isn't at all what I want! How can I make the GridView realise the data is decimal, not text, and sort correctly. I am almost at the point where I might just insert the numbers back into SQL as decimal, and then read it back in sorted! Thanks

    N 1 Reply Last reply
    0
    • A AaronM_NZ

      I am working on a project and I am a bit stumped with sorting of a Gridview. I am creating a DataTable, and one of the columns is populated with decimal numbers ranging from -100.00 to +100.00. I then DataBind the DataTable to the GridView, and then sort on the column. The problem is its sorting it as text, not as decimal numbers - so its sorted something like this: 9.33, -7.6, 3.3, 2.02, 14.6, -1.8, -1, 0.99, etc which isn't at all what I want! How can I make the GridView realise the data is decimal, not text, and sort correctly. I am almost at the point where I might just insert the numbers back into SQL as decimal, and then read it back in sorted! Thanks

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

      Do you have all column type specified for your data table ? If yes, take a DataView from it and use sort functions on the DataView and bind DataView to the grid.

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

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

        Do you have all column type specified for your data table ? If yes, take a DataView from it and use sort functions on the DataView and bind DataView to the grid.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        A Offline
        A Offline
        AaronM_NZ
        wrote on last edited by
        #3

        Thank you, that has worked! (dt.Columns.Add("_SortColumn_").DataType = System.Type.GetType("System.Decimal"))

        N 1 Reply Last reply
        0
        • A AaronM_NZ

          Thank you, that has worked! (dt.Columns.Add("_SortColumn_").DataType = System.Type.GetType("System.Decimal"))

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

          Glad to know it helped

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

          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