- Table,TableRow and TableCell Web Server Control
in ASP.NET environment,This article describes you how to work with Table,TableRow
and TableCell Web Control.The table,TableRow and TableCell are similar to the HTML
elements.The Table Web server control creates a general-purpose table on a Web Forms
page.
Rows in the table are created as TableRow Web server controls, and cells within
each row are implemented as TableCell Web server controls.
Web Server Table Vs Html Table
- HTML table.enables you to create a static table in a web page by specify
<table> element.you create HTML table when you are creating a static table
(one in which you will not add or change content at run time), do not create a Table
control.
- a <HTMLTable> can became a Table control when including the runat=server property
- Table that allows you to create and manipulate tables. for instance, adding
rows or cells via server code.
The Table Web server control can be easier to program than the HtmlTable control
because it offers an object model with typed properties that is consistent with
other Web server controls. (The model is also consistent between the Table, TableRow,
and TableCell controls.)
Web Server Table Vs Other List Web Server Controls
- he list controls are data-bound. The list controls work only against a data source,
whereas the Table control can display any combination of HTML text and controls,
whether or not they are data-bound.
- The list controls use templates to specify the layout of their elements. The Table
control supports the TableCell child control, which you can fill as you would any
HTML <td> element.
Binding Data to the Table Control
Although the Table control is not inherently data-bound, you can use it to display
data from a database.you can bind any property of a Table control to a data source
like as all other web control.
To Add Table Web Server Controls to a Page
- Type <asp:Table></asp:Table> element in a Page
- (or) From the Standard tab of the Toolbox, drag a Table control onto the page.
To add rows and cells to a Table Web server control at design time
- Select the table, then open the Properties window and click the ellipsis button(..)
for the Rows property.
- Click Add to create a new row.
- To add cells to the new row, make sure the row is selected in the Members list,
and then click the ellipsis button (..) for the Cells property.
- Click Add to create a new cell
To add rows and cells to a Table Web server control Programmatically,
the following code snippets demonstrates create rows and columns at run time.
-
in .aspx.cs page,
-
Protected void Button1_Click (object sender, System.EventArgs e)
{
for(int i=1; i <= 3; i++) {
// Create a new row and add it to the table.
TableRow row1 = new TableRow();
tbl1.Rows.Add(row1);
for (int j = 1; j <= 9; j++) {
// Create a new cell and add it to the row.
TableCell cell1 = new TableCell();
row1.Cells.Add(cell1);
// Mock up a product ID.
string prodID = rowCtr + "_" + cellCtr;
// Add a Label text as control.
cell1.Controls.Add(new Label("Name: "));
// Create a Hyperlink Web server control and add it to the cell.
System.Web.UI.WebControls.HyperLink lnk = new HyperLink();
lnk.Text = "welcome"+Convert.ToString(j);
lnk.NavigateUrl = "http://www.yoursite.com/";
cell1.Controls.Add(lnk);
}
}
}
-
- Related Links
-
46362f3d-dd3e-447d-8f09-5cc1378d3c43|0|.0