homepage Welcome to WebmasterWorld Guest from 23.22.173.58
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
2 colum table with ASP result set
How can I do this?
newnewbie1




msg:956350
 6:07 am on Nov 24, 2002 (gmt 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!

 

txbakers




msg:956351
 6:21 am on Nov 24, 2002 (gmt 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




msg:956352
 6:45 am on Nov 24, 2002 (gmt 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

newnewbie1




msg:956353
 1:48 pm on Nov 24, 2002 (gmt 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!

duckhunter




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

Take a look at the Table object

System.Web.UI.WebControls

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

duckhunter




msg:956355
 2:40 pm on Nov 24, 2002 (gmt 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>

AussieStu




msg:956356
 2:16 am on Dec 6, 2002 (gmt 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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved