Web Server Controls->ASP.NET Table Control

Definition and Usage

The Table control is used in conjunction with the TableCell control and the TableRow control to create a table.


Properties

Property Description
BackImageUrl A URL to an image to use as an background for the table
BorderWidth The width of the border around the table
CellPadding The space between the cell walls and contents
CellSpacing The space between cells
GridLines The gridlines in the table. Legal values are:
  • None
  • Horizontal
  • Vertical
  • Both
HorizontalAlign The horizontal alignment of the table in the page. Legal values are:
  • Center
  • Justify
  • Left
  • NotSet
  • Right
id A unique id for the control
runat Specifies that the control is a server control.  Must be set to "server"

Examples

Table
ASPX Source:

<html>
<body>

<form runat=server>
<asp:Table runat="server" CellPadding="5"
GridLines="horizontal" HorizontalAlign="Center">
   <asp:TableRow>
     <asp:TableCell>1</asp:TableCell>
     <asp:TableCell>2</asp:TableCell>
   </asp:TableRow>
   <asp:TableRow>
     <asp:TableCell>3</asp:TableCell>
     <asp:TableCell>4</asp:TableCell>
   </asp:TableRow>
</asp:Table>
<br />
<asp:Table runat="server" CellPadding="5"
GridLines="vertical" HorizontalAlign="Center">
   <asp:TableRow>
     <asp:TableCell>1</asp:TableCell>
     <asp:TableCell>2</asp:TableCell>
   </asp:TableRow>
   <asp:TableRow>
     <asp:TableCell>3</asp:TableCell>
     <asp:TableCell>4</asp:TableCell>
   </asp:TableRow>
</asp:Table>
</form>

</body>
</html>

Output Result:
1 2
3 4

1 2
3 4

In this example we declare two Table controls in an .aspx file.

Table 2
ASPX Source:

<script  runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
dim rows,cells,j,i
rows=3
cells=2
For j=0 To rows-1
   dim r As New TableRow()
   For i=0 To cells-1
     dim c As New TableCell()
     c.Controls.Add(New LiteralControl("row " & j & ", cell " & i))
     r.Cells.Add(c)
   Next
   Table1.Rows.Add(r)
Next
End Sub
</script>

<html>
<body>

<form runat="server">
<asp:Table id="Table1" BorderWidth="1" GridLines="Both" runat="server" />
</form>

</body>
</html>

Output Result:
row 0, cell 0 row 0, cell 1
row 1, cell 0 row 1, cell 1
row 2, cell 0 row 2, cell 1

In this example we declare a Table control, three TableRow controls, and two TableCell controls in an .aspx file.

posted on 2007-03-27 10:19  改变热爱  阅读(249)  评论(0)    收藏  举报

导航