Welcome to WebmasterWorld Guest from 50.17.117.221

Forum Moderators: ocean10000

Message Too Old, No Replies

2 colum table with ASP result set

How can I do this?

     
6:07 am on Nov 24, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 27, 2002
posts:99
votes: 0


Hi!

I've got a Query that is bring back a result set- it's a list of doctors. I would like to make this a 2 column table and list the doctors side by side.

There's 18 doctors, and I'd like to have 9 rows with 2 columns... I can't figure out how to do this...

If the record count is odd I would like to print that record in the left had column, if it's even, I'd like to print it in the right hand column...

Here part of my code:

<td class="formRegPurple" valign="top">
<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center">
<%
do until recData.EOF %>
<tr>
<td class="formRegPurple">
<input type="radio" name="DoctorID" value="<%=recData.Fields("DoctorID")%>" <% if recData.Fields("DoctorID") = session("DoctorID") then%> checked <%end if %>>
<%=recData.Fields("DoctorName")%>
<td><tr>
<% recData.movenext
Loop
%>

Can anybody think of how to do this?
I am STUCK!

6:21 am on Nov 24, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
posts:4392
votes: 0


I do this quite often. Here is the code for doing it in 3 columns. You can adapt it.

first, I declare some variables up in the top:
var numstu = rsStudents.RecordCount;
var sally = Math.round(numstu/3);
var betty = sally * 2;

Then, here is the first of the 3 columns:
<td width="269" height="11" class="xxtxt">
<% if (rsStudents.EOF) { %>&nbsp;<% } else { %>
<% for (var i=0; i < sally ; i++) { %>
<%=(rsStudents.Fields.Item("first").value)%><br>
<% rsStudents.MoveNext(); if (rsStudents.EOF){break} %>
<% } %>
<% } %>
</td>

finally, the other columns start this way:
<% for (var i=betty ; i < numstu ; i++) { %>

and

<% while (!rsStudents.EOF) { %>

And there you have three columns.

Woz

6:45 am on Nov 24, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member woz is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 13, 2000
posts:4823
votes: 0


I do it a little differently, and perhaps not so elegantly, but it also seems to work.

dim some variables such as strLeft and strRight

and do something like this

for i = 0 to TotalRecords
if RecordCount =< (TotalRecords/2) then
StrLeft = "what ever you want"
else
strRight = "whatever you want"
end if
ors.movenext

Then populate the two halves of a table with strLeft and strRight, remebering to get them on the correct side. ;)

Onya
Woz

1:48 pm on Nov 24, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 27, 2002
posts:99
votes: 0


OH, I see what you are doing, but I don't think that's quite what I want. I want to paint the table horizontally...

My result set is 18 doctors, I want to have a table that looks like this:

Doctor1 Doctor2
Doctor3 Doctor4
Doctor5 Doctor6
Doctor7 Doctor8
Doctor9 Doctor10
Doctor11 Doctor12
Doctor13 Doctor14
Doctor15 Doctor16
Doctor17 Doctor18

How can I do populate the left side, then the right side of the table?

Thanks!

2:27 pm on Nov 24, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 28, 2002
posts:506
votes: 0


Take a look at the Table object

System.Web.UI.WebControls

[edited by: duckhunter at 2:40 pm (utc) on Nov. 24, 2002]

2:40 pm on Nov 24, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 28, 2002
posts:506
votes: 0


Here ya go.

Code Behind Loading Dynamically

Imports System.Web.UI
Imports System.Web.UI.WebControls

Dim numrows As Integer = 3
Dim numcells As Integer = 2

Dim j As Integer
For j = 0 To numrows - 1
Dim r As New TableRow()
Dim i As Integer
For i = 0 To numcells - 1
Dim c As New TableCell()
c.Controls.Add(New LiteralControl("row " & j.ToString() & ", cell " & i.ToString()))
r.Cells.Add(c)
Next i
Table1.Rows.Add(r)
Next j

HTML Code

<B>Table Example, constructed programmatically</B>
<form runat="server" ID="Form1">
<asp:Table id="Table1" GridLines="Both" HorizontalAlign="Center" Font-Name="Verdana" Font-Size="8pt" CellPadding="5" CellSpacing="0" Runat="server" />
</form>

2:16 am on Dec 6, 2002 (gmt 0)

New User

10+ Year Member

joined:May 23, 2002
posts:17
votes: 0


Well I'm probably too late to help you out but here goes anyway. I'm gunna try to do it with your code so as to be sure that you'll be able to figure out how it goes:

<td class="formRegPurple" valign="top">
<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center">
<% do until recData.EOF %>
<tr>
<td class="formRegPurple">
<input type="radio" name="DoctorID" value="<%=recData.Fields("DoctorID")%>" <% if recData.Fields("DoctorID") = session("DoctorID") then%> checked <%end if %>>
<%=recData.Fields("DoctorName")%>
</td>
<td class="formRegPurple">
<% recData.movenext
if not recData.EOF then %>
<input type="radio" name="DoctorID" value="<%=recData.Fields("DoctorID")%>"
<% if recData.Fields("DoctorID") = session("DoctorID") then%>
checked <%end if %>>
<%=recData.Fields("DoctorName")%>
<% else %>
&nbsp;
<% end if %>
</td></tr>
<% recData.movenext
Loop %>

You just put in another <td> .. </td> just like your first one and put an &nbsp; in it if you run out of records.

To me that's the simplest way to do it (and that's a good thing!).

Cheers!