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. Sorting GridView according an IP column

Sorting GridView according an IP column

Scheduled Pinned Locked Moved ASP.NET
databasecsssql-serversysadminalgorithms
3 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.
  • 3 Offline
    3 Offline
    3nbar A7mad A
    wrote on last edited by
    #1

    Hi, I have a page that displays data in GridView. The data is obtained from an SQL Server database. One column is an IP addresses, which are stored as VarChar(15) in the database. The page executes a select statemnet and bind the GridView with the DataTable obtained by executing this SQL statement. The problem is that I want to allow the user to sort the Grid according to the IPs column. Taking into consideration, that IP 10.5.0.0 should come before 10.30.0.0 in ascending sorting. So, I can't rely on the built in sorting of the GridView. Kind regards, Ahmed

    I 1 Reply Last reply
    0
    • 3 3nbar A7mad A

      Hi, I have a page that displays data in GridView. The data is obtained from an SQL Server database. One column is an IP addresses, which are stored as VarChar(15) in the database. The page executes a select statemnet and bind the GridView with the DataTable obtained by executing this SQL statement. The problem is that I want to allow the user to sort the Grid according to the IPs column. Taking into consideration, that IP 10.5.0.0 should come before 10.30.0.0 in ascending sorting. So, I can't rely on the built in sorting of the GridView. Kind regards, Ahmed

      I Offline
      I Offline
      indianet
      wrote on last edited by
      #2

      You can always create a computed column that brings the numerical value of the ipaddress then override the SortCommand and specify the computed column as the sort expression

      3 1 Reply Last reply
      0
      • I indianet

        You can always create a computed column that brings the numerical value of the ipaddress then override the SortCommand and specify the computed column as the sort expression

        3 Offline
        3 Offline
        3nbar A7mad A
        wrote on last edited by
        #3

        I was looking forward for something like the Sort function of the System.Array class, to which I can pass a class implementing IComparer. It seems there is no other way than that indianet had posted. Thanks indianet for your help.

        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