A Table object contains more than one row TableRow, and each row contains tablecell,tablecell that can contain additional HTML or server controls as Web server controls.
One, the properties in the table
Table object:
Backimageurl | The
URL of the background image for the table |
Caption |
Table title |
Captionalign |
Title Text alignment |
cellpadding |
The amount of space (in pixels) between the contents of the table cell and the cell border |
CellSpacing |
The amount of space between adjacent cells |
Rows |
A collection of rows in a table control |
TableRow object:
horizontalalign |
Gets or sets the horizontal alignment of the row contents |
VerticalAlign |
Gets or sets the vertical alignment of the row contents |
Cells |
Gets a collection of TableCell objects that represent the cells of the rows in the table control |
TableCell object:
ColumnSpan |
Gets or sets the number of columns that a cell spans in a table |
RowSpan |
Number of rows spanned |
Text |
Gets or sets the text of a cell |
Second, the example code
Click the button to produce the background code for the table:
Copy Code code as follows:
protected void Button1_Click (object sender, EventArgs e)
{
int a =int. Parse (Dropdownlist1.selectedvalue); Used to get the number of rows
int b = Int. Parse (Dropdownlist2.selectedvalue); The number of columns to take, int. Parse (); the same effect as Convert.ToInt32 is to convert to integral type.
Table1.bordercolor = System.Drawing.Color.DarkGoldenrod;
Table1.borderwidth = 2; These two sentences are used to set the properties of the table
for (int i = 0; i < A; i++)
{
TableRow w = new TableRow (); Instantiating a Row object
for (int j = 0; J < b; j + +)
{
TableCell q = new TableCell (); Instantiating a Cell object
Q.backcolor = System.Drawing.Color.Blue; Sets the background color property of a cell.
Button R = New button (); Instantiates the button object to add to the table.
if (i = = 2 && j = = 2)//To add a button to the third row, the third column
{
Q.controls.add (R); Add a button to a cell and add another control to the same method
}
Q.borderwidth = 2;
W.cells.add (q); Adds a cell to a row.
}
TABLE1.ROWS.ADD (w); Add a row to a table
}
}
Screenshot of Run Effect: