asp.net table controls how to use _ Basic application

Source: Internet
Author: User

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:

The
BackimageurlURL 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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.