Nested Tables
[Previous] [Main] [Next]

 
Nested tables are tables in which a cell contains another entire table. Since htmlTableCell inherits from htmlGroup, it can contain other html++ objects, including other tables. Nested tables are often used to align page elements, such as when producing multicolumn text pages or when laying out product specification sheets.  
 
 
Example
 
#include <stdio.h>  
#include <stdlib.h>  
#include <dcmicro/htmlpp/htmlpp.h>  
 
int main( void )  
{  
   htmlCgi   server ;  
   htmlPage  page( "html++ example application" ) ;  
 
   htmlTable  table ;  
   table.Border(3)  
        .Align(align_center)  
        .CellPadding(10)  
        .Width("75%") ;  
 
   htmlTable  accounts ;  
   accounts.Width( "100%" ) ;  
 
   htmlTable  options ;  
   options.Width( "100%" ) ;  
 
   accounts << ( htmlTableRow() << htmlBold("Plan" )  
                                << htmlBold("Monthly Price")  
                                << htmlBold("Setup Fee" ) )  
            << ( htmlTableRow() << "Basic"  
                                << "$14.95"  
                                << "$20.00" )  
            << ( htmlTableRow() << "Enhanced"  
                                << "$19.95"  
                                << "$20.00" )  
            << ( htmlTableRow() << "The Works"  
                                << "$24.95"  
                                << "$20.00" ) ;  
 
   options  
     << ( htmlTableRow()  
           << htmlBold( "Feature" )  
           << htmlTableCell( htmlBold( "Monthly Price" ), align_right ) )  
     << ( htmlTableRow()  
           << "Extra Email Address"  
           << htmlTableCell( "$4.95", align_right ) )  
     << ( htmlTableRow()  
           << "Personal Web Site"  
           << htmlTableCell( "FREE", align_right ) )  
     << ( htmlTableRow()   
           << "10MB additional storage"  
           << htmlTableCell( "$9.95", align_right ) ) ;  
 
   table << htmlCenter(  
              htmlFont("", +2, "Dialup Internet Accounts"))  
         << "The following service plans and options are "  
            "available for your internet surfing pleasure."  
         << accounts  
         << options ;  
 
   page << table ;  
 
   server << page ;  
   return 0 ;  
}  
 
Program Output
 
Content-Type: text/html  
<HTML>  
<HEAD>  
<TITLE>html++ example application</TITLE>  
</HEAD>  
<BODY>  
<TABLE BORDER="3" ALIGN="CENTER" CELLPADDING="10" WIDTH="75%">  
<TR><TD><CENTER><FONT SIZE="+2">Dialup Internet Accounts</FONT></CENTER></TD>  
</TR>  
<TR><TD>The following service plans and options are available for your internet surfing pleasure.</TD>  
</TR>  
<TR><TD><TABLE WIDTH="100%">  
<TR><TD><B>Plan</B></TD>  
<TD><B>Monthly Price</B></TD>  
<TD><B>Setup Fee</B></TD>  
</TR>  
<TR><TD>Basic</TD>  
<TD>$14.95</TD>  
<TD>$20.00</TD>  
</TR>  
<TR><TD>Enhanced</TD>  
<TD>$19.95</TD>  
<TD>$20.00</TD>  
</TR>  
<TR><TD>The Works</TD>  
<TD>$24.95</TD>  
<TD>$20.00</TD>  
</TR>  
</TABLE>  
</TD>  
</TR>  
<TR><TD><TABLE WIDTH="100%">  
<TR><TD><B>Feature</B></TD>  
<TD ALIGN="RIGHT"><B>Monthly Price</B></TD>  
</TR>  
<TR><TD>Extra Email Address</TD>  
<TD ALIGN="RIGHT">$4.95</TD>  
</TR>  
<TR><TD>Personal Web Site</TD>  
<TD ALIGN="RIGHT">FREE</TD>  
</TR>  
<TR><TD>10MB additional storage</TD>  
<TD ALIGN="RIGHT">$9.95</TD>  
</TR>  
</TABLE>  
</TD>  
</TR>  
</TABLE>  
</BODY>  
</HTML>  
 

ex_tablenested.gif  

 


©1998 DC Micro Development. All rights reserved.
No portion of this document may be c opied or reproduced without expressed written consent.
html++ is a trademark of DC Micro Development.