TableItemStyle Class
Assembly: System.Web (in system.web.dll)
The TableItemStyle class represents the style properties for an element of a control that renders as a TableRow or TableCell. You can control the vertical and horizontal alignment of the contents in an item of the table by setting the HorizontalAlign and VerticalAlign properties, respectively. You can also specify whether the contents of the cell automatically continue on the next line when the end of the cell is reached by setting the Wrap property.
This class provides methods that are useful for creating a style for an item in the Table control. You can use the CopyFrom and MergeWith methods to copy or merge the style properties of another TableItemStyle with the instance of the TableItemStyle that the method is called from.
The following code example creates several rows in a Table control and applies a TableItemStyle object to each row.
<%@ page language="C#" %> <%@ Import Namespace="System.Drawing" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> private void Page_Load(object sender, System.EventArgs e) { // Create a TableItemStyle object that can be // set as the default style for all cells // in the table. TableItemStyle tableStyle = new TableItemStyle(); tableStyle.HorizontalAlign = HorizontalAlign.Center; tableStyle.VerticalAlign = VerticalAlign.Middle; tableStyle.Width = Unit.Pixel(100); // Create more rows for the table. for (int rowNum = 2; rowNum < 10; rowNum++) { TableRow tempRow = new TableRow(); for (int cellNum = 0; cellNum < 3; cellNum++) { TableCell tempCell = new TableCell(); tempCell.Text = String.Format("({0},{1})", rowNum, cellNum); tempRow.Cells.Add(tempCell); } Table1.Rows.Add(tempRow); } // Apply the TableItemStyle to all rows in the table. foreach (TableRow rw in Table1.Rows) foreach (TableCell cel in rw.Cells) cel.ApplyStyle(tableStyle); // Create a header for the table. TableHeaderCell header = new TableHeaderCell(); header.RowSpan = 1; header.ColumnSpan = 3; header.Text = "Table of (x,y) Values"; header.Font.Bold = true; header.BackColor = Color.Gray; header.HorizontalAlign = HorizontalAlign.Center; header.VerticalAlign = VerticalAlign.Middle; // Add the header to a new row. TableRow headerRow = new TableRow(); headerRow.Cells.Add(header); // Add the header row to the table. Table1.Rows.AddAt(0, headerRow); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>TableCell Example</title> </head> <body> <form id="form1" runat="server"> <div> <h1>TableCell Example</h1> <asp:table id="Table1" runat="server" CellPadding="3" CellSpacing="3" Gridlines="both"> <asp:TableRow> <asp:TableCell Text="(0,0)" /> <asp:TableCell Text="(0,1)" /> <asp:TableCell Text="(0,2)" /> </asp:TableRow> <asp:TableRow> <asp:TableCell Text="(1,0)" /> <asp:TableCell Text="(1,1)" /> <asp:TableCell Text="(1,2)" /> </asp:TableRow> </asp:table> </div> </form> </body> </html>
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.