HTML Controls->ASP.NET HtmlTableRow Control
Definition and Usage
The HtmlTableRow control is used to control a <tr> element. In HTML, the <tr> element is used to create a table row.
Properties
| Property | Description |
|---|---|
| Align | The alignment of the row |
| Attributes | Returns all attribute name and value pairs of the element |
| BGColor | The background color of the row |
| BorderColor | The color of the borders |
| Cells | Returns the cells in this row |
| Disabled | A Boolean value that indicates whether or not the control should be disabled. Default is false |
| Height | The height of the row |
| id | A unique id for the control |
| InnerHtml | Sets or returns the content between the opening and closing tags of the HTML element. Special characters are not automatically converted to HTML entities |
| InnerText | Sets or returns all text between the opening and closing tags of the HTML element. Special characters are automatically converted to HTML entities |
| runat | Specifies that the control is a server control. Must be set to "server" |
| Style | Sets or returns the CSS properties that are applied to the control |
| TagName | Returns the element tag name |
| VAlign | The vertical alignment of cells in the row |
| Visible | A Boolean value that indicates whether or not the control should be visible |
Examples
HTMLTable
ASPX Source:
| <script runat="server"> Sub submit(sender As Object, e As EventArgs) Dim row,numrows,numcells,j,i row=0 numrows=cint(rows1.Value) numcells=cint(cells1.Value) for j=1 to numrows Dim r As New HtmlTableRow() row=row+1 for i=1 to numcells Dim c As New HtmlTableCell() c.Controls.Add(New LiteralControl("row " & j & ", cell " & i)) r.Cells.Add(c) next t1.Rows.Add(r) t1.Visible=true next End Sub </script> <html> <body> <form runat="server"> <p>Table rows: <select id="rows1" runat="server"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <br />Table cells: <select id="cells1" runat="server"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <br /><br /> <input type="submit" value="Display Table" runat="server" OnServerClick="submit"> </p> <table id="t1" border="1" runat="server" visible="false"/> </form> </body> </html> |
Output Result:
|
Table rows: |
IF you select the selectbox "Table rows" "2" and "Table cells"2, it will shows :
|
Table rows:
|
In this example we declare two HtmlSelect controls, one HtmlInputButton control, and one HtmlTable control in an .aspx file (remember to embed the controls inside an HtmlForm control). The user may choose number of cells and rows. When the submit button is triggered, the submit subroutine is executed. The submit subroutine generates the table based on what the user did input.
HTMLTable 2
ASPX Source:
| <script runat="server"> Sub submit(sender As Object, e As EventArgs) dim i,j table1.BGColor="yellow" table1.BorderColor="red" for i=0 To table1.Rows.Count-1 for j=0 To table1.Rows(i).Cells.Count-1 table1.Rows(i).Cells(j).InnerHtml="Row " & i next next End Sub </script> <html> <body> <form runat="server"> <table id="table1" border="1" runat="server"> <tr> <td>Cell 1</td> <td>Cell 2</td> </tr> <tr> <td>Cell 3</td> <td>Cell 4</td> </tr> </table> <br /> <input type="button" value="Change Contents" OnServerClick="submit" runat="server"/> </form> </body> </html> |
Output Result:
|
IF you click the button "Change Contents", it will shows :
|
In this example we declare an HtmlTable control and an HtmlInputButton control in an .aspx file (remember to embed the controls inside an HtmlForm control). When the submit button is triggered, the submit subroutine is executed. The submit subroutine modifies the background color and the border color of the table, it also changes the contents of the cells.
浙公网安备 33010602011771号