创建一个服务器端控件,该控件映射到 <td> 和 <th> HTML 元素并允许您操作表中的单元格。
<td|th
EnableViewState="False|True"
Id="string"
Visible="False|True"
OnDataBinding="OnDataBinding event handler"
OnDisposed="OnDisposed event handler"
OnInit="OnInit event handler"
OnLoad="OnLoad event handler"
OnPreRender="OnPreRender event handler"
OnUnload="OnUnload event handler"
runat="server"
>
CellContent
</td|/th> |
备注
使用
HtmlTableCell 类使您可以控制各个独立单元格的外观。通过设置
注意 |
|---|
|
同一行中的所有单元格都具有相同的高度。一行中最高的单元格确定该行中所有单元格的高度。 |
通过设置
HtmlTableCell 类使您可以通过设置
注意 |
|---|
|
合并单元格时,请确保表中的各行具有相同的长度。还应确保各列具有相同的高度。否则,表可能不会按预期的方式显示。 |
示例
下面的示例演示如何使用 HtmlTableCell 对象修改
| Visual Basic? | 复制代码 |
|---|---|
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlTableCell Control</title>
<script runat="server">
Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim i As Integer
Dim j As Integer
' Iterate through the rows of the table.
For i = 0 To Table1.Rows.Count - 1
' Iterate through the cells of a row.
For j = 0 To Table1.Rows(i).Cells.Count - 1
' Change the inner HTML of the cell.
Table1.Rows(i).Cells(j).InnerHtml = "Row " & i.ToString() _
& ", Column " & _
j.ToString()
Next j
Next i
End Sub
</script>
</head>
<body>
<form id="Form1" runat="server">
<h3>HtmlTableCell Example</h3>
<table id="Table1"
Border="1"
BorderColor="black"
runat="server">
<tr>
<td>
Cell 1
</td>
<td>
Cell 2
</td>
</tr>
<tr>
<td>
Cell 3
</td>
<td>
Cell 4
</td>
</tr>
</table>
<br><br>
<input id="Button1" type="button"
value="Change Table Contents"
OnServerClick = "Button_Click"
runat="server"/>
</form>
</body>
</html>
| |
| C#? | 复制代码 |
|---|---|
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlTableCell Control</title>
<script runat="server">
void Button_Click(Object sender, EventArgs e)
{
// Iterate through the rows of the table.
for (int i=0; i<=Table1.Rows.Count - 1; i++)
{
// Iterate through the cells of a row.
for (int j=0; j<=Table1.Rows[i].Cells.Count - 1; j++)
{
// Change the inner HTML of the cell.
Table1.Rows[i].Cells[j].InnerHtml = "Row " + i.ToString() +
", Column " +
j.ToString();
}
}
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<h3>HtmlTableCell Example</h3>
<table id="Table1"
Border="1"
BorderColor="black"
runat="server">
<tr>
<td>
Cell 1
</td>
<td>
Cell 2
</td>
</tr>
<tr>
<td>
Cell 3
</td>
<td>
Cell 4
</td>
</tr>
</table>
<br><br>
<input id="Button1" type="button"
value="Change Table Contents"
OnServerClick = "Button_Click"
runat="server"/>
</form>
</body>
</html>
| |
请参见
注意