Home / ASP.NET Wiki / HTML / Web Controls / Table

Table

 Rate It (2)

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.

Revision number 6, Thursday, June 26, 2008 4:02:20 AM by k_nitin_r

Comments

Good to say that using Server.HtmlEncode(TestString); we can help the security vulnerabilities.

Related Articles

Shuffle DataRow in DataTable

We all know that we can sort the rows in DataTable by making a simple use of DefaultView. But now if i want a few conditional rows to be shuffled in the table; i dont have anything inbuilt in .net.Now if I want to select a few conditional rows in the table

Full Text Search using Sql Server 2005-08

Recently i came to work on sql server 2005 & 08 and full text search. i want to share some interesting point which i came to know in couple of hours. there are steps you need to follow for the quicj start.1) check whether full text services is running

Simple Survey Application

Introduction: The companies which are offering variety of services to the customers, they need to get the response from the customers in many forms. By analyzing these responses companies will have an overview of their services and performance. The surveys

Shortcuts

Table of Contents

Top Wiki Contributors

(last 30 days)

  1. abiruban (1)