Export (0) Print
Expand All

HtmlTable Constructor

Initializes a new instance of the HtmlTable class.

[Visual Basic]
Public Sub New()
[C#]
public HtmlTable();
[C++]
public: HtmlTable();
[JScript]
public function HtmlTable();

Remarks

Use this constructor to create and initialize a new instance of the HtmlTable class.

The following table shows initial property values for an instance of HtmlTable.

Property Initial Value
TagName The "table" literal string.

Example

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
   <script runat="server" >
  
      Sub Page_Load(sender As Object, e As EventArgs)

         ' Create the HtmlTable control.
         Dim table As HtmlTable = New HtmlTable()
         table.Border = 1
         table.CellPadding = 3

         ' Populate the HtmlTable control.

         Dim rowcount As Integer
         Dim cellcount As Integer
          
         ' Create the rows of the table.
         For rowcount=0 to 4

            Dim row As HtmlTableRow = New HtmlTableRow()
            
            ' Create the cells of a row. 
            For cellcount=0 to 3
          
               Dim cell As HtmlTableCell

               ' Create table header cells for first row.
               If rowcount <= 0 Then
             
                  cell = New HtmlTableCell("th")
           
               Else
               
                  cell = New HtmlTableCell()
               
               End If

               ' Create the text for the cell.
               cell.Controls.Add(new LiteralControl( _
                   "row " & rowcount.ToString() & ", " & _
                   "column " & cellcount.ToString()))

               ' Add the cell to the Cells collection of a row. 
               row.Cells.Add(cell)
               
            Next cellcount

            ' Add the row to the Rows collection of the table.
            table.Rows.Add(row)
          
         Next rowcount
 
         ' Add the control to the Controls collection of the 
         ' PlaceHolder control.
         Place.Controls.Clear()
         Place.Controls.Add(table)
         
      End Sub
  
   </script>
  
<body>

   <form runat="server">
  
      <h3> HtmlTable Example </h3> 
  
      <asp:PlaceHolder id="Place" runat="server"/>
  
   </form>

</body>
</html>
 

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
   <script runat="server" >
  
      void Page_Load(Object sender, EventArgs e)
      {

         // Create the HtmlTable control.
         HtmlTable table = new HtmlTable();
         table.Border = 1;
         table.CellPadding = 3;

         // Populate the HtmlTable control.
          
         // Create the rows of the table.
         for(int rowcount=0; rowcount<5; rowcount++)
         {
            HtmlTableRow row = new HtmlTableRow();
            
            // Create the cells of a row. 
            for(int cellcount=0; cellcount<4; cellcount++)
            {
               HtmlTableCell cell;

               // Create table header cells for first row.
               if(rowcount <= 0)
               {
                  cell = new HtmlTableCell("th");
               }
               else
               {
                  cell = new HtmlTableCell();
               }

               // Create the text for the cell.
               cell.Controls.Add(new LiteralControl(
                   "row " + rowcount.ToString() + ", " + 
                   "column " + cellcount.ToString()));

               // Add the cell to the Cells collection of a row. 
               row.Cells.Add(cell);
               
            }

            // Add the row to the Rows collection of the table.
            table.Rows.Add(row);
          
         }
 
         // Add the control to the Controls collection of the 
         // PlaceHolder control.
         Place.Controls.Clear();
         Place.Controls.Add(table);
         
      }
  
   </script>
  
<body>

   <form runat="server">
  
      <h3> HtmlTable Example </h3> 
  
      <asp:PlaceHolder id="Place" runat="server"/>
  
   </form>

</body>
</html>
 

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlTable Class | HtmlTable Members | System.Web.UI.HtmlControls Namespace

Show:
© 2014 Microsoft