Professional Web Applications Themes

ORDER BY clause in asp.net dataset - Adobe Dreamweaver & Contribute

I have an aspx page on which is a dataset created in DWMX. The sql query is described in the line CommandText='<%# 'SELECT * FROM booklist ' %>' I want to be able to sort the list and the consequent page in different ways dynamically. In classic ASP I would do this by passing a querystring back to the page (like pasge.asp?sortorder=id) and it was easy to fix the querystring to accept a parameter. But in .net I cant do this, I have tried adding a parameter in the MX query-invoking dialog but the result CommandText='<%# 'SELECT * FROM booklist ...

  1. #1

    Default ORDER BY clause in asp.net dataset

    I have an aspx page on which is a dataset created in DWMX. The sql query is
    described in the line CommandText='<%# 'SELECT * FROM booklist ' %>' I want
    to be able to sort the list and the consequent page in different ways
    dynamically. In classic ASP I would do this by passing a querystring back to
    the page (like pasge.asp?sortorder=id) and it was easy to fix the querystring
    to accept a parameter. But in .net I cant do this, I have tried adding a
    parameter in the MX query-invoking dialog but the result CommandText='<%#
    'SELECT * FROM booklist ORDER BY sortorder' %>' - although it tests
    correctly in the dialog - once sent and tested on the server produces an SQL
    server message saying that I must supply a column name in order to be able to
    use ORDER BY. (but I am !!) I can use CommandText='<%# 'SELECT * FROM
    booklist ORDER BY ' + request.querystring('sortorder') %>' , that works but of
    course falls over if the page is called without the querystring. Can anyone
    help me in re-sorting a datalist dynamically?

    davidxtaylor Guest

  2. #2

    Default Re: ORDER BY clause in asp.net dataset

    Hi

    I had exactly the same problem with a site I did last year
    (pharmacyhealthlink.org)
    Basically I did something like this, checked to see if param was available
    and if not set a default

    <script runat="server>
    dim mySortOrder
    dim myCmd

    sub page_load

    if Request.Params("sortorder") = "" then
    mySortOrder = "ASC"
    else
    mySortOrder = Request.Params("sortorder")
    end if

    myCmd = "Select * from booklist Order By " + mySortOrder
    end sub
    </script>

    And then
    CommandText='<%# myCmd %>'

    Hope this helps


    "davidxtaylor" <webforumsusermacromedia.com> wrote in message
    news:cv7k9h$q9a$1forums.macromedia.com...
    >I have an aspx page on which is a dataset created in DWMX. The sql query is
    > described in the line CommandText='<%# 'SELECT * FROM booklist ' %>' I
    > want
    > to be able to sort the list and the consequent page in different ways
    > dynamically. In classic ASP I would do this by passing a querystring back
    > to
    > the page (like pasge.asp?sortorder=id) and it was easy to fix the
    > querystring
    > to accept a parameter. But in .net I cant do this, I have tried adding a
    > parameter in the MX query-invoking dialog but the result CommandText='<%#
    > 'SELECT * FROM booklist ORDER BY sortorder' %>' - although it tests
    > correctly in the dialog - once sent and tested on the server produces an
    > SQL
    > server message saying that I must supply a column name in order to be able
    > to
    > use ORDER BY. (but I am !!) I can use CommandText='<%# 'SELECT * FROM
    > booklist ORDER BY ' + request.querystring('sortorder') %>' , that works
    > but of
    > course falls over if the page is called without the querystring. Can
    > anyone
    > help me in re-sorting a datalist dynamically?
    >

    ossie Guest

Similar Threads

  1. Re-arranging order of DataSet
    By citizen-erazed in forum Macromedia Flash Data Integration
    Replies: 5
    Last Post: September 27th, 03:09 PM
  2. Strange results of ORDER BY clause when item begins with slash orbackslash
    By SCassidy@overlandstorage.com in forum PostgreSQL / PGSQL
    Replies: 1
    Last Post: January 19th, 09:36 PM
  3. Where Clause: Order of Precedence
    By GH in forum ASP Database
    Replies: 2
    Last Post: July 20th, 08:09 PM
  4. Trouble with ORDER BY clause
    By Peroq in forum ASP
    Replies: 15
    Last Post: October 23rd, 09:07 PM
  5. ORDER BY clause causes read-only recordset
    By Brian in forum Microsoft SQL / MS SQL Server
    Replies: 6
    Last Post: July 9th, 07:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139