Export (0) Print
Expand All

TableCellCollection Class

Encapsulates a collection of TableHeaderCell and TableCell objects that make up a row in a Table control. This class cannot be inherited.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

'Declaration
Public NotInheritable Class TableCellCollection
	Implements IList, ICollection, IEnumerable
'Usage
Dim instance As TableCellCollection

public final class TableCellCollection implements IList, ICollection, 
	IEnumerable
public final class TableCellCollection implements IList, ICollection, 
	IEnumerable

Use this class to programmatically manage a collection of TableCell objects that make up a row in a Table control. This class is commonly used to add or remove cells from a row in a Table control.

NoteNote

A Table control contains a Rows collection that represents a collection of TableRow objects. Each TableRow represents an individual row in the table and contains a Cells collection that represents a collection of TableCell objects. These TableCell objects represent the individual cells in the table. To get an individual cell, you must first get a TableRow from the Rows collection of a Table control. You can then get a TableCell from the Cells collection of the TableRow.

The following example demonstrates how to programmatically fill a Table control. TableCell objects, which represent individual cells, are added to TableRow objects, which represent the individual rows, through the Cells property.


<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
 <head>
 
    <script runat="server">

        Sub Page_Load(sender As Object, e As EventArgs)
            ' Generate rows and cells.           
            Dim numrows As Integer = 4
            Dim numcells As Integer = 6
            Dim counter As Integer = 1
            Dim j As Integer
            For j = 0 To numrows - 1
                Dim r As New TableRow()
                Dim i As Integer
                For i = 0 To numcells - 1
                    Dim c As New TableCell()
                    c.Text = counter.ToString()
                    counter += 1
                    r.Cells.Add(c)
                Next i
                Table1.Rows.Add(r)
            Next j
        End Sub

        Sub Button_Click_Coord(sender As Object, e As EventArgs)            
            Dim i As Integer
            For i = 0 To Table1.Rows.Count - 1
                Dim j As Integer
                For j = 0 To (Table1.Rows(i).Cells.Count) - 1                    
                    Table1.Rows(i).Cells(j).Text = "(" & j.ToString() & _
                        ", " & i.ToString() & ")"
                Next j
            Next i 
        End Sub

        Sub Button_Click_Number(sender As Object, e As EventArgs)
            Dim counter As Integer = 1
            
            Dim i As Integer
            For i = 0 To Table1.Rows.Count - 1
                Dim j As Integer
                For j = 0 To (Table1.Rows(i).Cells.Count) - 1                    
                    Table1.Rows(i).Cells(j).Text = counter.ToString()
                    counter += 1
                Next j 
            Next i
        End Sub
 
    </script>
 
 </head>
 
 <body>
 
    <h3>TableCellCollection Example</h3>
    <form runat="server">
       <asp:Table id="Table1" 
            runat="server"/>
       <br>
       <center>
          <asp:Button id="Button1"
               Text="Display Table Coordinates"
               OnClick="Button_Click_Coord"
               runat="server"/>
          <asp:Button id="Button2"
               Text="Display Cell Numbers"
               OnClick="Button_Click_Number"
               runat="server"/>
       </center>
 
    </form>
 
 </body>
 </html>
    

System.Object
  System.Web.UI.WebControls.TableCellCollection

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft