TableRowCollection.RemoveAt(Int32) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从 TableRow 中移除位于指定索引位置的 TableRowCollection。
public:
virtual void RemoveAt(int index);
public void RemoveAt (int index);
abstract member RemoveAt : int -> unit
override this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)
参数
- index
- Int32
要从 TableRow 移除的 TableRowCollection 对象的索引。
实现
示例
以下示例演示如何使用 RemoveAt 方法从表中删除行。 请注意,在示例中, Rows 的 Table 属性是 类的 TableRowCollection 实例。 另请注意,集合的 Rows 索引是从零开始的。
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Text" %>
<!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 = 6
Dim counter As Integer = 1
Dim a_row As New ArrayList()
' 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()
rw.Cells.Add(cel)
counter += 1
Next
Table1.Rows.Add(rw)
Next
End Sub
Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
Table1.Rows.RemoveAt(2)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
<title>TableCellCollection Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>TableCellCollection Example</h3>
<asp:Table id="Table1" runat="server"/>
<br /> <br />
<asp:Button id="Button1"
Text="Remove middle row"
OnClick="Button_Click"
runat="server"/>
</div>
</form>
</body>
</html>
<%@ 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)
{
// Generate rows and cells.
int numRows = 5;
int numCells = 6;
int counter = 1;
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();
rw.Cells.Add(cel);
counter++;
}
Table1.Rows.Add(rw);
Table1.GridLines = GridLines.Both;
Table1.CellPadding = 4;
Table1.CellSpacing = 0;
}
}
void Button_Click(object sender, EventArgs e)
{
Table1.Rows.RemoveAt(2);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>TableCellCollection Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>TableCellCollection Example</h3>
<asp:Table id="Table1" runat="server"/>
<br /> <br />
<asp:Button id="Button1"
Text="Remove middle row"
OnClick="Button_Click"
runat="server"/>
</div>
</form>
</body>
</html>
注解
使用此方法从指定索引处的 TableRowCollection 中删除 TableRow 。