Table 控件与 TableCell 控件和 TableRow 控件配合,用于创建表格。
属性 | 描述 | .NET |
---|---|---|
BackImageUrl | 表格的背景图像的 URL。 | 1.0 |
Caption | 表格的标题。 | 2.0 |
CaptionAlign | 标题文本的对齐方式。 | 2.0 |
CellPadding | 单元格边框与内容的间距。 | 1.0 |
CellSpacing | 单元格间距。 | 1.0 |
GridLines | 表格的网格线格式 | 1.0 |
HorizontalAlign | 表格在页面中的水平对齐方式。 | 1.0 |
Rows | 表格中的行集合。 | 1.0 |
runat | 规定该控件是服务器控件。必须设置为 "server"。 | 1.0 |
- AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, CssClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled, SkinID, Style, TabIndex, ToolTip, Width
- AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls, EnableTheming, EnableViewState, ID, NamingContainer, Page, Parent, Site, TemplateControl, TemplateSourceDirectory, UniqueID, Visible
Table
- <!DOCTYPE html>
- <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>
在本例中,我们在 .aspx 文件中声明了两个 Table 控件。
Table 2
- <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>
- <!DOCTYPE html>
- <html>
- <body>
- <form runat="server">
- <asp:Table id="Table1" BorderWidth="1" GridLines="Both" runat="server" />
- </form>
- </body>
- </html>
在本例中,我们在 .aspx 文件中声明了一个 Table 控件,三个 TableRow 控件,和两个 TableCell 控件。