Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > sorting table into 2 columns

Reply
Thread Tools

sorting table into 2 columns

 
 
Raphael Gluck
Guest
Posts: n/a
 
      04-01-2004
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


 
Reply With Quote
 
 
 
 
Manohar Kamath [MVP]
Guest
Posts: n/a
 
      04-01-2004
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" <(E-Mail Removed)> wrote in message
news:eE46e3$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Raphael Gluck
Guest
Posts: n/a
 
      04-01-2004
Wow, thanks for all that help!
Thanks
"Manohar Kamath [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:eE46e3$(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
ljb
Guest
Posts: n/a
 
      04-01-2004
"Raphael Gluck" <(E-Mail Removed)> wrote in message
news:eE46e3$(E-Mail Removed)...

> 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


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      04-01-2004
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Align table columns with gridview columns Jacksm ASP .Net 2 11-21-2006 09:49 PM
database columns vs. gui columns and sorting ittay.dror@gmail.com Java 5 03-04-2006 10:48 AM
convert rows to columns and columns to rows helpful sql ASP .Net 0 05-19-2005 06:03 PM
Table Widget for IE? Fixed header, sorting columns, etc Matt Kruse Javascript 17 09-03-2004 12:00 AM
Sorting columns in a table or form Mike S. Nowostawsky Javascript 0 12-28-2003 04:54 AM



Advertisments