TableCellCollection Class
Encapsulates a collection of TableHeaderCell and TableCell objects that make up a row in a Table control. This class cannot be inherited.
Assembly: System.Web (in System.Web.dll)
The TableCellCollection type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Count | Gets the number of TableCell objects in the TableCellCollection. |
![]() | IsReadOnly | Gets a value indicating whether the TableCellCollection is read-only. |
![]() | IsSynchronized | Gets a value indicating whether access to the TableCellCollection is synchronized (thread-safe). |
![]() | Item | Gets a TableCell from the TableCellCollection at the specified index. |
![]() | SyncRoot | Gets the object that can be used to synchronize access to the TableCellCollection. |
| Name | Description | |
|---|---|---|
![]() | Add | Appends the specified TableCell to the end of the TableCellCollection. |
![]() | AddAt | Adds the specified TableCell to the TableCellCollection at the specified index location. |
![]() | AddRange | Appends the TableCell objects from the specified array to the end of the collection. |
![]() | Clear | Removes all TableCell objects from the TableCellCollection. |
![]() | CopyTo | Copies the items from the TableCellCollection to the specified System.Array, starting with the specified index in the System.Array. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetCellIndex | Returns a value that represents the index of the specified TableCell from the TableCellCollection. |
![]() | GetEnumerator | Returns a System.Collections.IEnumerator implemented object that contains all TableCell objects in the TableCellCollection. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | Remove | Removes the specified TableCell from the TableCellCollection. |
![]() | RemoveAt | Removes a TableCell from the TableCellCollection at the specified index. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() | AsParallel | Enables parallelization of a query. (Defined by ParallelEnumerable.) |
![]() | AsQueryable | Converts an IEnumerable to an IQueryable. (Defined by Queryable.) |
![]() | Cast(Of TResult) | Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.) |
![]() | OfType(Of TResult) | Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.) |
| Name | Description | |
|---|---|---|
![]() ![]() | IList.Add | Infrastructure. Adds an object to the collection. |
![]() ![]() | IList.Contains | Infrastructure. Determines whether the specified object is contained within the collection. |
![]() ![]() | IList.IndexOf | Infrastructure. Searches for the specified object and returns the zero-based index of the first occurrence within the collection. |
![]() ![]() | IList.Insert | Infrastructure. Inserts an object into the collection at the specified index. |
![]() ![]() | IList.IsFixedSize | Infrastructure. For a description of this member, see IsFixedSize. |
![]() ![]() | IList.Item | Infrastructure. For a description of this member, see Item. |
![]() ![]() | IList.Remove | Infrastructure. Removes an object from the collection. |
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.
Note |
|---|
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" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Private 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 rowNum As Integer Dim cellNum As Integer For rowNum = 0 To numrows - 1 Dim rw As New TableRow() 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 End Sub Private Sub Button_Click_Coord(sender As Object, e As EventArgs) Dim rowNum As Integer Dim cellNum As Integer Dim rowCount As Integer For rowCount = 0 To Table1.Rows.Count - 1 For cellNum = 0 To (Table1.Rows(rowNum).Cells.Count) - 1 Table1.Rows(rowNum).Cells(cellNum).Text = _ String.Format("(Row{0}, Cell{1})", rowNum, cellNum) Next Next End Sub Private Sub Button_Click_Number(sender As Object, e As EventArgs) Dim counter As Integer = 1 Dim rowNum As Integer Dim cellNum As Integer For rowNum = 0 To Table1.Rows.Count - 1 For cellNum = 0 To (Table1.Rows(rowNum).Cells.Count) - 1 Table1.Rows(rowNum).Cells(cellNum).Text = _ counter.ToString() counter += 1 Next 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"/> <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> </div> </form> </body> </html>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

