Click here to Skip to main content
15,881,757 members
Articles / Web Development / HTML
Article

Table

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Oct 2013CPOL1 min read 6K   1  
The Table class allows you to build an HTML table and specify its characteristics. A table can be built at design time with static content, but the

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

The Table class allows you to build an HTML table and specify its characteristics. A table can be built at design time with static content, but the Table control is often built programmatically with dynamic contents

Each Table control is made up of rows (represented by instances of the TableRow class) stored in the Rows collection of the control. Each row is made up of cells (represented by instances of the TableCell class) stored in the Cells collection of the each TableRow.

Here is some sample code on adding rows and cells to a Table control:

TableCell tcell1 = new TableCell();
tcell1.Text =  "Cell1";
TableRow trow1 = new TableRow();
trow1.Cells.Add(tcell1);
table1.Rows.Add(trow1);

You can display an image in the background of the Table control by setting the BackImageUrl property. By default, the horizontal alignment of the items in the table is not set. If you want to specify the horizontal alignment, set the HorizontalAlignment property. The spacing between individual cells is controlled by the CellSpacing property. You can specify the amount of space between the contents of a cell and the cell's border by setting the CellPadding property. To display the cell borders, set the GridLines property. You can display the horizontal lines, vertical lines, or both horizontal and vertical lines.

Text is not HTML encoded before it is displayed in the Table control. This makes it possible to embed script within HTML tags in the text. If the values for the control come from user input, be sure to validate the values to help prevent security vulnerabilities.

We can use Server.HtmlEncode(String) to make sure that no direct javascript can be embedded in the HTML because of the use of the control.

This article was originally posted at http://wiki.asp.net/page.aspx/335/table

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

754 members

Comments and Discussions

 
-- There are no messages in this forum --