System.Web.UI.WebControls Namespace
Constructs a table and defines its properties.
Visibility |
Constructor |
Parameters |
public |
Table |
( )
|
|
The Table class allows you to build an HTML table and specify its characteristics in a straightforward manner, using the same abstract object model for building any other Web controls. A table can be built at design time given some static contents, but the power of a Table control is often realized when the table is built programmatically with dynamic contents. In addition, as for other Web controls, the same code to render a table yields appropriate output accordingly for both downlevel and uplevel browsers.
Example 1 illustrates how to create a table at design time. The TableRow and TableCell Web controls are also used in the process. In this example, the table contains 2 rows of 2 cells each, with both horizontal and vertical gridlines, and is aligned to the center of the page.
Example 2 illustrates how to construct a table programmatically. First, you add contents to a table cell by adding ( literal controls, and so on ) to its Controls collection. Then you add TableCell objects to the table row's Cells collection. After that, you add the TableRow objects to the table's Rows collection. For this example, constants are assigned to the number of rows and columns, but often they come from user input controls ( such as ListBox, and so on ).
It is important to remember that any programmatic addition or modification of table rows or cells will not persist across postbacks. It is because table rows and cells are controls of their own, and not properties of controls. Therefore, any changes of table rows or cells should be reconstructed after each postback. In fact, if substantial modifications are expected, it is recommended that DataList or DataGrid controls be used instead of Table controls. As a result, this Table class is primarily used by control developers.