HtmlTableCellCollection.Item Property (Int32)
Gets the HtmlTableCell object at the specified index from the HtmlTableCellCollection collection.
Assembly: System.Web (in System.Web.dll)
Parameters
- index
-
Type:
System.Int32
An ordinal index value that specifies the HtmlTableCell to return.
Property Value
Type: System.Web.UI.HtmlControls.HtmlTableCellAn HtmlTableCell that represents a cell contained in the HtmlTableCellCollection.
Use this indexer to get an HtmlTableCell object from the HtmlTableCellCollection collection. You can access an HtmlTableCell object at a specified index by using simple array notation.
Note |
|---|
The collection is zero-based; therefore, the first element in the collection contains an index value of 0. |
The following code example demonstrates how to use the indexer to retrieve a cell of a table, represented by an HtmlTableCell object, from the HtmlTableCellCollection collection. The cell is then updated with new content. Notice that the Cells property of a row represented by an HtmlTableRow object is the HtmlTableCellCollection collection.
<%@ Page Language="VB" AutoEventWireup="True" %> <!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 i As Integer Dim j As Integer Dim row As HtmlTableRow Dim cell As HtmlTableCell ' Get the number of rows and columns selected by the user. Dim numrows As Integer = CInt(Select1.Value) Dim numcells As Integer = CInt(Select2.Value) ' Iterate through the rows. For j = 0 To numrows - 1 ' Create a new row and add it to the Rows collection. row = New HtmlTableRow() ' Provide a different background color for alternating rows. If (j Mod 2) = 1 Then row.BgColor = "Gray" End If ' Iterate through the cells of a row. For i = 0 To numcells - 1 ' Create a new cell and add it to the Cells collection. cell = New HtmlTableCell() cell.Controls.Add(New LiteralControl("row " & _ j.ToString() & _ ", cell " & _ i.ToString())) row.Cells.Add(cell) Next i Table1.Rows.Add(row) Next j End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>HtmlTableCellCollection Example</title> </head> <body> <form id="form1" runat="server"> <h3>HtmlTableCellCollection Example</h3> <table id="Table1" style="border-width:1; border-color:Black; padding:5" cellspacing="0" runat="server"/> <hr /> Select the number of rows and columns to create: <br /><br /> Table rows: <select id="Select1" runat="server"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> Table cells: <select id="Select2" runat="server"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <br /><br /> <input type="submit" value="Generate Table" runat="server"/> </form> </body> </html>
Available since 1.1
