TableCellCollection.Remove(TableCell) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从 TableCell 中移除指定的 TableCellCollection。
public:
void Remove(System::Web::UI::WebControls::TableCell ^ cell);
public void Remove (System.Web.UI.WebControls.TableCell cell);
member this.Remove : System.Web.UI.WebControls.TableCell -> unit
Public Sub Remove (cell As TableCell)
参数
- cell
- TableCell
要从 TableCell 移除的 TableCellCollection。
示例
以下示例演示如何使用 Remove 方法从表中删除中心列。 请注意,在示例中, Cells 的 TableRow 属性是 类的 TableCellCollection 实例。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
int numRows = 5;
int numCells = 7;
int counter = 1;
TableCell remove;
// Create a table;
for (int rowNum = 0; rowNum < numRows; rowNum++)
{
TableRow rw = new TableRow();
for (int cellNum = 0; cellNum < numCells; cellNum++)
{
TableCell cel = new TableCell();
cel.Text = counter.ToString();
counter++;
rw.Cells.Add(cel);
}
Table1.Rows.Add(rw);
}
// Remove the center column.
for (int rowNum = 0; rowNum < numRows; rowNum++)
{
remove = Table1.Rows[rowNum].Cells[3];
Table1.Rows[rowNum].Cells.Remove(remove);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TableCellCollection Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>TableCellCollection Example</h3>
<asp:Table id="Table1" runat="server" />
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim numrows As Integer = 5
Dim numcells As Integer = 7
Dim counter As Integer = 1
Dim remove As TableCell
' Create a table.
Dim rowNum As Integer
For rowNum = 0 To numrows - 1
Dim rw As New TableRow()
Dim cellNum As Integer
For cellNum = 0 To numcells - 1
Dim cel As New TableCell()
cel.Text = counter.ToString()
counter += 1
rw.Cells.Add(cel)
Next
Table1.Rows.Add(rw)
Next
' Remove the center column.
For rowNum = 0 To numrows - 1
remove = Table1.Rows(rowNum).Cells(3)
Table1.Rows(rowNum).Cells.Remove(remove)
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TableCellCollection Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>TableCellCollection Example</h3>
<asp:Table id="Table1" runat="server" />
</div>
</form>
</body>
</html>
注解
使用此方法从 TableCellCollection中删除指定的 TableCell 。