A little help with getrows()

Discussion in 'ASP General' started by j1c, Nov 16, 2004.

  1. j1c

    j1c Guest

    I'm using getrows to return the values from two columns in a MSSQL sql
    database. Looping through them like so:
    dim irowloop, icolloop, i
    for irowloop = 0 to ubound(instances, 2)
    for icolloop = 0 to ubound(instances, 1)
    response.write("<option value=""VAL"">") 'get 2nd col val
    response.write(i(icolloop, irowloop))
    response.write("</option>")
    next
    next

    How can I get the value of the second column into the VALUE=""
    attribute in the drop down?
    j1c, Nov 16, 2004
    #1
    1. Advertising

  2. "j1c" <> wrote in message
    news:...
    > I'm using getrows to return the values from two columns in a MSSQL sql
    > database. Looping through them like so:
    > dim irowloop, icolloop, i
    > for irowloop = 0 to ubound(instances, 2)
    > for icolloop = 0 to ubound(instances, 1)
    > response.write("<option value=""VAL"">") 'get 2nd col val
    > response.write(i(icolloop, irowloop))
    > response.write("</option>")
    > next
    > next
    >
    > How can I get the value of the second column into the VALUE=""
    > attribute in the drop down?
    >


    Response.Write "<option value='" & Server.HTMLEncode(instances(1,irowloop))
    & "'>"
    Chris Hohmann, Nov 16, 2004
    #2
    1. Advertising

  3. j1c

    j1c Guest

    Sorry, but I am not sure I completely understand how that works.

    Your example gives just what I was looking for, however the content
    between the <option> tags now show both column values as items in the
    drop down.
    j1c, Nov 16, 2004
    #3
  4. j1c wrote:
    > Sorry, but I am not sure I completely understand how that works.
    >
    > Your example gives just what I was looking for, however the content
    > between the <option> tags now show both column values as items in the
    > drop down.


    The array created from GetRows has two dimensions. The first dimension
    corresponds to the column number, the second to the row number. To reference
    the first column in the first row, you would say
    getrowsarray(0,0)
    (remember, the indexes are zero-based).
    To reference the second column in the first row, you would do say
    getrowsarray(1,0)
    3rd column, second row:
    getrowsarray(2,1)

    clear?

    I don't know why you're using a nested loop. Assuming you want the data in
    the second column to be the value, and the data in the first column to be
    the text, this should do what you want:

    for irowloop = 0 to ubound(instances, 2)
    Response.Write "<option value='" & _
    Server.HTMLEncode(instances(1,irowloop)) & "'>"
    response.write Server.HTMLEncode(instances(0, irowloop))
    response.write("</option>")
    next

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Nov 16, 2004
    #4
  5. j1c

    j1c Guest

    Great - thank you Bob!
    j1c, Nov 16, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Croney69

    Using GetRows()

    Croney69, Jul 28, 2003, in forum: ASP General
    Replies:
    5
    Views:
    160
    Bob Barrows
    Jul 28, 2003
  2. Moshe

    GetRows Mystery

    Moshe, Aug 28, 2003, in forum: ASP General
    Replies:
    8
    Views:
    122
    Bob Barrows
    Aug 28, 2003
  3. Crane Linkledder

    Difference between getrows and getstring

    Crane Linkledder, Oct 29, 2003, in forum: ASP General
    Replies:
    11
    Views:
    252
    Aaron Bertrand - MVP
    Oct 30, 2003
  4. Jim

    GetRows Random <td></td> Output

    Jim, Nov 21, 2003, in forum: ASP General
    Replies:
    1
    Views:
    106
    Jeff Clark
    Nov 22, 2003
  5. j1c

    A little help with getrows()

    j1c, Nov 16, 2004, in forum: ASP General
    Replies:
    0
    Views:
    102
Loading...

Share This Page