ASP.NET TableCell 控件
定义和用法
TableCell 控件与 Table 控件和 TableRow 控件结合,用于创建表格中的单元格。
提示:每行的单元均存储在 TableRow 控件的 Cells 集合中。
属性
属性 |
描述 |
.NET |
AssociatedHeaderCellID |
与 TableCell 控件关联的表标题单元格列表。 |
2.0 |
ColumnSpan |
单元格跨越的列数。 |
1.0 |
HorizontalAlign |
表格单元格中内容的水平对齐方式。 |
1.0 |
RowSpan |
单元格跨越的行数。 |
1.0 |
runat |
规定该控件是服务器控件。必须设置为 "server"。 |
1.0 |
Text |
规定表格单元格的文本。 |
1.0 |
VerticalAlign |
表格单元格中内容的垂直对齐方式。 |
1.0 |
Wrap |
规定单元格内容是否换行。 |
1.0 |
Web 控件标准属性
1 | AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, CssClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled, SkinID, Style, TabIndex, ToolTip, Width
|
控件标准属性
1 | AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls, EnableTheming, EnableViewState, ID, NamingContainer, Page, Parent, Site, TemplateControl, TemplateSourceDirectory, UniqueID, Visible
|
实例
Table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <!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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <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 控件。