Sorting Database Table in sql server 2000

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nagmvs
    New Member
    • Aug 2008
    • 49

    Sorting Database Table in sql server 2000

    Hello,
    (Sql Server 2000 & ASP)

    There is one table in my data base with 20 rows and 8 columns.and i wnat to Sort those data when i click Cloumns individually.Su ppose when i click First column in my table the total data in the table will be sorted.What is the code for that in Asp with sql server 2000.

    Thanks,
    Nagesh.
  • JamieHowarth0
    Recognized Expert Contributor
    • May 2007
    • 537

    #2
    Can a mod please move this to ASP forum and I will then help the poster accordingly as this is not a SQL Server question.

    Regards,

    medicineworker

    Comment

    • JamieHowarth0
      Recognized Expert Contributor
      • May 2007
      • 537

      #3
      Hi Nagesh,

      Firstly, you need to display the column headings in a table-like structure, then for each column heading, you need to set the heading to be a link, and pass a parameter (e.g. orderby=column-name).
      Then, in your SQL code in your ASP page, you do a test to see whether the column to be ordered by has been specified:

      [code=asp]
      If Request.QuerySt ring("order-by") <> "" Then
      If Request.QuerySt ring("order-dir") <> "" Then
      strSQL = strSQL + " ORDER BY " + Request.QuerySt ring("order-by") + " " + Request.QuerySt ring("order-dir")
      Else
      strSQL = strSQL + " ORDER BY " + Request.QuerySt ring("order-by")
      End If
      End If
      [/code]

      Then, your links will look something like this:
      [code=html]
      <tr>
      <td><a href="yourpage. asp?order-by=title&order-dir=asc">Title</a></td>
      <td><a href="yourpage. asp?order-by=FName&order-dir=asc">FName</a></td>
      <td><a href="yourpage. asp?order-by=LName&order-dir=asc">LName</a></td>
      etc. etc.
      </tr>
      [/code]

      Hope this helps.

      Best regards,

      medicineworker

      Comment

      • imtmub
        New Member
        • Nov 2006
        • 112

        #4
        Use grid view function in asp. you can sort any column.

        Comment

        • DrBunchman
          Recognized Expert Contributor
          • Jan 2008
          • 979

          #5
          Originally posted by imtmub
          Use grid view function in asp. you can sort any column.
          The GridView is used in ASP.NET not Classic ASP.

          Dr B

          Comment

          Working...