sorting table into 2 columns

R

Raphael Gluck

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
 
M

Manohar Kamath [MVP]

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.
 
R

Raphael Gluck

Wow, thanks for all that help!
Thanks
Manohar Kamath said:
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


from
 
L

ljb

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
 
E

Evertjan.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top