sorting table into 2 columns

Discussion in 'ASP General' started by Raphael Gluck, Apr 1, 2004.

  1. Hi
    I have a simple ASP question.
    I am experimenting a little with asp, and I am trying to view a page from a
    database.
    The thing is, i am seeing all my data, in one long column.
    How can I split it up into two columns.
    I have created a no jargon page, just for the example,
    http://www.tripakltd.com/check.asp
    the source code is
    http://www.tripakltd.com/check.txt


    I hope someone can help me with this

    Thanks so much

    Raphael
     
    Raphael Gluck, Apr 1, 2004
    #1
    1. Advertising

  2. One way (of many) is to create two variables hold alternate values from the
    recordset

    Dim column1, column2
    Dim counter

    column1 = "<td width=50%>"
    column2 = "<td width=50%>"

    ' Initialize the counter
    counter = 0

    ' This is your while loop
    While. ...

    ' Alternate adding value to the string
    If counter Mod 2 = 0 Then
    ' Add the checkbox and recordset value to the first string
    column1 = column1 & "<input type=checkbox ....." &
    rsFeedback("....")
    Else
    ' Add the checkbox and recordset value to the second string
    column2 = column2 & "<input type=checkbox ....." &
    rsFeedback("....")
    End If

    ' Complete the TD tag
    column1 = column1 & "</td>"
    column2 = column2 & "</td>"

    ' Now, print the values of these variables
    Response.Write("<table><tr>")
    Response.Write(column1)
    Response.Write(column2)
    Response.Write("</tr></table>")

    rsFeedback.MoveNext
    Wend

    This is not the most efficient way, since you are concatenating strings.
    Another way, especially if you have a count of records (say using
    disconnected recordset), is to use RecordCount property of the recordset to
    count upto the half for one TD, and start another TD, and Response.Write all
    the way:

    ' Make sure you can somehow read recordcount (disconnected RS, etc)
    halfCount = Int(rsFeedBack.RecordCount/2)
    Counter = 0

    ' Start the first TD
    Response.Write("<table><tr>")
    Response.Write("<td>")

    ' This is your while loop
    While. ...

    ' Check to see if half the count has passed
    If counter > halfCount Then
    ' End the previous TD and Start a new TD
    Response.Write("</td><td>")
    End If

    ' Print the values
    Response.Write("<input type=checkbox....>")
    Response.Write(rsFeedback("..."))

    rsFeedback.MoveNext
    Wend

    Hope that helps.

    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "Raphael Gluck" <> wrote in message
    news:eE46e3$...
    > Hi
    > I have a simple ASP question.
    > I am experimenting a little with asp, and I am trying to view a page from

    a
    > database.
    > The thing is, i am seeing all my data, in one long column.
    > How can I split it up into two columns.
    > I have created a no jargon page, just for the example,
    > http://www.tripakltd.com/check.asp
    > the source code is
    > http://www.tripakltd.com/check.txt
    >
    >
    > I hope someone can help me with this
    >
    > Thanks so much
    >
    > Raphael
    >
    >
     
    Manohar Kamath [MVP], Apr 1, 2004
    #2
    1. Advertising

  3. Wow, thanks for all that help!
    Thanks
    "Manohar Kamath [MVP]" <> wrote in message
    news:...
    > One way (of many) is to create two variables hold alternate values from

    the
    > recordset
    >
    > Dim column1, column2
    > Dim counter
    >
    > column1 = "<td width=50%>"
    > column2 = "<td width=50%>"
    >
    > ' Initialize the counter
    > counter = 0
    >
    > ' This is your while loop
    > While. ...
    >
    > ' Alternate adding value to the string
    > If counter Mod 2 = 0 Then
    > ' Add the checkbox and recordset value to the first string
    > column1 = column1 & "<input type=checkbox ....." &
    > rsFeedback("....")
    > Else
    > ' Add the checkbox and recordset value to the second string
    > column2 = column2 & "<input type=checkbox ....." &
    > rsFeedback("....")
    > End If
    >
    > ' Complete the TD tag
    > column1 = column1 & "</td>"
    > column2 = column2 & "</td>"
    >
    > ' Now, print the values of these variables
    > Response.Write("<table><tr>")
    > Response.Write(column1)
    > Response.Write(column2)
    > Response.Write("</tr></table>")
    >
    > rsFeedback.MoveNext
    > Wend
    >
    > This is not the most efficient way, since you are concatenating strings.
    > Another way, especially if you have a count of records (say using
    > disconnected recordset), is to use RecordCount property of the recordset

    to
    > count upto the half for one TD, and start another TD, and Response.Write

    all
    > the way:
    >
    > ' Make sure you can somehow read recordcount (disconnected RS, etc)
    > halfCount = Int(rsFeedBack.RecordCount/2)
    > Counter = 0
    >
    > ' Start the first TD
    > Response.Write("<table><tr>")
    > Response.Write("<td>")
    >
    > ' This is your while loop
    > While. ...
    >
    > ' Check to see if half the count has passed
    > If counter > halfCount Then
    > ' End the previous TD and Start a new TD
    > Response.Write("</td><td>")
    > End If
    >
    > ' Print the values
    > Response.Write("<input type=checkbox....>")
    > Response.Write(rsFeedback("..."))
    >
    > rsFeedback.MoveNext
    > Wend
    >
    > Hope that helps.
    >
    > --
    > Manohar Kamath
    > Editor, .netWire
    > www.dotnetwire.com
    >
    >
    > "Raphael Gluck" <> wrote in message
    > news:eE46e3$...
    > > Hi
    > > I have a simple ASP question.
    > > I am experimenting a little with asp, and I am trying to view a page

    from
    > a
    > > database.
    > > The thing is, i am seeing all my data, in one long column.
    > > How can I split it up into two columns.
    > > I have created a no jargon page, just for the example,
    > > http://www.tripakltd.com/check.asp
    > > the source code is
    > > http://www.tripakltd.com/check.txt
    > >
    > >
    > > I hope someone can help me with this
    > >
    > > Thanks so much
    > >
    > > Raphael
    > >
    > >

    >
    >
     
    Raphael Gluck, Apr 1, 2004
    #3
  4. Raphael Gluck

    ljb Guest

    "Raphael Gluck" <> wrote in message
    news:eE46e3$...

    > How can I split it up into two columns.
    > I have created a no jargon page, just for the example,
    > http://www.tripakltd.com/check.asp


    One way or another you need to determine how many rows your recordset
    contains. Then open an html table placing half the records in cell one with
    each record followed by <br>. Close cell one, open cell two and place the
    rest there. I prefer this because alphabetically sorted records read from
    top down rather than across two columns. I usually place all my records into
    an array with rs.getrows. It makes it easy to jump directly to an element or
    use ubound() to get an accurate count of records since ADO often doesn't
    provide one.

    LJB
     
    ljb, Apr 1, 2004
    #4
  5. Raphael Gluck

    Evertjan. Guest

    ljb wrote on 01 apr 2004 in microsoft.public.inetserver.asp.general:
    > One way or another you need to determine how many rows your recordset
    > contains. Then open an html table placing half the records in cell one
    > with each record followed by <br>. Close cell one, open cell two and
    > place the rest there. I prefer this because alphabetically sorted
    > records read from top down rather than across two columns. I usually
    > place all my records into an array with rs.getrows. It makes it easy
    > to jump directly to an element or use ubound() to get an accurate
    > count of records since ADO often doesn't provide one.


    Making a real "dual vertical sorted" table is relatively easy:

    response.write "<table>" & VbCrLf
    for rec=0 to numberOfRecords-1 step 2
    response.write "<tr>"
    insertCell(rec)
    insertCell(rec+numberOfRecords\2) ' integer division
    response.write "</tr>" & VbCrLf
    next
    response.write "</table>" & VbCrLf


    function insertCell(rec)
    response.write "<td>"
    if rec<=numberOfRecords then response.write arrayRecord(rec)
    response.write "</td>"
    end sub

    not tested

    a three column vertical sorted table is not much more work

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Apr 1, 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. helpful sql
    Replies:
    0
    Views:
    830
    helpful sql
    May 19, 2005
  2. Replies:
    5
    Views:
    612
  3. Jacksm
    Replies:
    2
    Views:
    860
    Paul Chalekian
    Nov 21, 2006
  4. Mike S. Nowostawsky

    Sorting columns in a table or form

    Mike S. Nowostawsky, Dec 28, 2003, in forum: Javascript
    Replies:
    0
    Views:
    82
    Mike S. Nowostawsky
    Dec 28, 2003
  5. Matt Kruse
    Replies:
    17
    Views:
    242
    Mick White
    Sep 3, 2004
Loading...

Share This Page