다음을 통해 공유


TableRowCollection.Clear 메서드

정의

TableRow에서 TableRowCollection 컨트롤을 모두 제거합니다.

public:
 virtual void Clear();
public void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()

구현

예제

다음 예제에서는 사용 하는 방법을 보여 줍니다.는 Clear 모든 개체 TableRowCollection 를 제거 TableRow 하는 방법을 보여 줍니다는 테이블의 개체를 새 TableRow 개체로 대체 합니다.

<%@ 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">
    int numrows = 5;
    int numcells = 6;
    int counter = 1;

    void Page_Load(Object sender, EventArgs e)
    {

        // 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);
        }
        Table1.GridLines = GridLines.Both;
        Table1.CellPadding = 4;
        Table1.CellSpacing = 0;
    }

    void Button_Click(Object sender, EventArgs e)
    {

        // Clear the table.
        Table1.Rows.Clear();

        // Create new rows and cells.
        for (int rowNum = 0; rowNum < numrows; rowNum++)
        {
            TableRow rw = new TableRow();
            for (int cellNum = 0; cellNum < numcells; cellNum++)
            {
                TableCell cel = new TableCell();
                cel.Text = "***";
                rw.Cells.Add(cel);
            }
            Table1.Rows.Add(rw);
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Programmatic Table</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>Programmatic Table Example</h3>
        <asp:Table id="Table1" runat="server"/>

        <asp:Button id="Button1"
            Text="Replace All Rows With ***"
            OnClick="Button_Click"
            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">
    Dim numrows As Integer = 5
    Dim numcells As Integer = 6
    Dim counter As Integer = 1

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            
        ' 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)
            Table1.GridLines = GridLines.Both
            Table1.CellPadding = 4
            Table1.CellSpacing = 0
        Next
    End Sub

    Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
            
        ' Clear the table.
        Table1.Rows.Clear()
            
        ' Create new rows and cells.
        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 = "***"
                rw.Cells.Add(cel)
            Next
            Table1.Rows.Add(rw)
        Next
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Programmatic Table</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>Programmatic Table Example</h3>
        <asp:Table id="Table1" runat="server"/>

        <asp:Button id="Button1"
            Text="Replace All Rows With ***"
            OnClick="Button_Click"
            runat="server"/>
    </div>
    </form>
</body>
</html>

설명

에서 모든 TableRow 개체 TableRowCollection 를 제거하고 속성을 0으로 설정 Count 하려면 이 메서드를 사용합니다.

적용 대상

추가 정보