Table表格控件
主要对象
ASP.NET名称 | HTML名称 | 说明 |
Table | <table> | TableRow控件的父级控件 |
TableRow | <tr> | TableCell控件的父级控件 |
TableCell | <td> | 包含显示内容 |
TableHeaderRow | <thead> | 标题行元素 |
TableHeaderCell | <th> | 显示标题单元格内容 |
TableFooterRow | <tfoot> | 脚注行元素 |
Table控件与数据视图控件的区别
控件 | 用法 | 说明 |
Table | 总体布局 | 可包含文本、HTML和其他控件 使用TableCell控制外观 不绑定数据,可包含数据绑定控件 |
Repeater | 只读数据 | 只读 使用模板控制外观 数据绑定 不分页显示 |
DataList | 可编辑列表 | 可编辑 数据绑定 不分页显示 |
DataGrid | 可编辑列表 | 可编辑 数据绑定 支持分页和排序显示 |
GridView | 可编辑列表 | 类似DataGrid,但功能更强 数据绑定 支持分页和排序显示 |
不继承自其他类的Table属性
名称 | 类型 | 值 | 说明 |
BackImageUrl | String |
| 表格背景图URL |
Caption | String |
| 表格标题 |
CaptionAlign |
| Top Bottom Left Right Noset | 指定HTML标题元素的格式 |
CellPadding | Interger |
| 单元格边框与内容之间的间距 |
CellSpacing | Interger |
| 相邻单元格之间的间距 |
GridLines |
| Both Horizontal Vertical None | 表格网线的样式 |
HorizontalAlign |
| Center Left Right | 在页面中水平对齐方式 |
Table行(TableRow控件)的属性
名称 | 类型 | 值 | 说明 |
HorizontalAlign |
|
| 行中所有单元格水平对齐方式 |
VerticalAlign |
|
| 行中所有单元格垂直对齐方式 |
Cells | TableCellCollection |
| 组成行的TableCell对象的集合 |
TableSection |
|
|
|
Table单元格(TableCell控件)的属性
名称 | 类型 | 值 | 说明 |
ColumnSpan | Integer |
| 单元格跨越列数 |
RowSpan | Integer |
| 单元格跨越行数 |
HorizontalAlign |
|
| 单元格水平对齐方式 |
VerticalAlign |
|
| 单元格垂直对齐方式 |
Text |
|
| 单元格包含的内容 |
Wrap |
|
| 表示是否自动换行(默认true) |
设定单元格宽带
Table1.Rows[0].Cells[0].Width= Unit.Pixel(100);
Table1.Rows[0].Cells[1].Width = Unit.Pixel(100);
Table1.Rows[0].Cells[2].Width = Unit.Pixel(200); //300像素
Table1.Rows[0].Cells[3].Width = Unit.Percentage(40);//40%
Table1.Width = Unit.Percentage(100);
//創建單元格對象
TableCellcText = new TableCell();
cText.Width =Unit.Percentage(20);
cText.Width = Unit.Pixel(200);