TableItemStyle 類別

定義

表示呈現為 TableRowTableCell 之控制項項目的樣式屬性。

public ref class TableItemStyle : System::Web::UI::WebControls::Style
public class TableItemStyle : System.Web.UI.WebControls.Style
type TableItemStyle = class
    inherit Style
Public Class TableItemStyle
Inherits Style
繼承
衍生

範例

下列程式碼範例會在 控制項中建立數個 Table 資料列,並將 物件套用 TableItemStyle 至每個資料列。

<%@ 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)
    {
//<Snippet4>
        // 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);
//</Snippet4>

//<Snippet5>
        // 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);
        }
//</Snippet5>

//<Snippet6>
        // Apply the TableItemStyle to all rows in the table.
        foreach (TableRow rw in Table1.Rows)
            foreach (TableCell cel in rw.Cells)
                cel.ApplyStyle(tableStyle);
//</Snippet6>

//<Snippet7>
        // 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);  
//</Snippet7>
    }
</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>
<%@ page language="VB" %>
<%@ 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 Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        '<Snippet4>
        ' Create a TableItemStyle object that can be
        ' set as the default style for all cells
        ' in the table.
        Dim tableStyle As New TableItemStyle()
        tableStyle.HorizontalAlign = HorizontalAlign.Center
        tableStyle.VerticalAlign = VerticalAlign.Middle
        tableStyle.Width = Unit.Pixel(100)
        '</Snippet4>
        '<Snippet5>
        ' Create more rows for the table.
        Dim rowNum As Integer
        For rowNum = 2 To 9
            Dim tempRow As New TableRow()
            Dim cellNum As Integer
            For cellNum = 0 To 2
                Dim tempCell As New TableCell()
                tempCell.Text = _
                    String.Format("({0},{1})", rowNum, cellNum)
                tempRow.Cells.Add(tempCell)
            Next
            Table1.Rows.Add(tempRow)
        Next
        '</Snippet5>

        '<Snippet6>
        ' Apply the TableItemStyle to all rows in the table.
        Dim rw As TableRow
        For Each rw In Table1.Rows
            Dim cel As TableCell
            For Each cel In rw.Cells
                cel.ApplyStyle(tableStyle)
            Next
        Next
        '</Snippet6>

        '<Snippet7>
        ' Create a header for the table.
        Dim header As 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.
        Dim headerRow As New TableRow()
        headerRow.Cells.Add(header)

        ' Add the header row to the table.
        Table1.Rows.AddAt(0, headerRow)
        '</Snippet7>
    End Sub
</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>

備註

類別 TableItemStyle 代表呈現為 TableRowTableCell 之控制項專案的樣式屬性。 您可以分別設定 HorizontalAlign 和 屬性,以控制資料表專案中內容的垂直和 VerticalAlign 水準對齊方式。 您也可以藉由設定 Wrap 屬性,指定儲存格的內容是否會自動在下一行繼續。

這個類別提供方法,可用於建立 控制項中 Table 專案的樣式。 您可以使用 CopyFromMergeWith 方法來複製或合併另一個 TableItemStyle 的樣式屬性,以及呼叫方法的 TableItemStyle 實例。

建構函式

TableItemStyle()

使用預設值,建立 TableItemStyle 類別的新執行個體。

TableItemStyle(StateBag)

使用指定的狀態包,建立 TableItemStyle 類別的新執行個體。

屬性

BackColor

取得或設定 Web 伺服器控制項的背景色彩。

(繼承來源 Style)
BorderColor

取得或設定 Web 伺服器控制項的框線色彩。

(繼承來源 Style)
BorderStyle

取得或設定 Web 伺服器控制項的框線樣式。

(繼承來源 Style)
BorderWidth

取得或設定 Web 伺服器控制項的框線寬度。

(繼承來源 Style)
CanRaiseEvents

取得值,指出元件是否能引發事件。

(繼承來源 Component)
Container

取得包含 IContainerComponent

(繼承來源 Component)
CssClass

取得或設定用戶端上 Web 伺服器控制項所呈現的階層式樣式表 (CSS)。

(繼承來源 Style)
DesignMode

取得值,指出 Component 目前是否處於設計模式。

(繼承來源 Component)
Events

取得附加在這個 Component 上的事件處理常式清單。

(繼承來源 Component)
Font

取得與 Web 伺服器控制項關聯的字型屬性。

(繼承來源 Style)
ForeColor

取得或設定 Web 伺服器控制項的前景色彩 (通常是文字的色彩)。

(繼承來源 Style)
Height

取得或設定 Web 伺服器控制項的高度。

(繼承來源 Style)
HorizontalAlign

取得或設定儲存格中內容的水平對齊。

IsEmpty

保護的 (Protected) 屬性。 取得值,指出狀態包中是否已定義任何樣式項目。

(繼承來源 Style)
IsTrackingViewState

傳回值,指出是否任何的樣式項目都已經在狀態包中定義。

(繼承來源 Style)
RegisteredCssClass

取得使用控制項註冊的階層式樣式表 (CSS) 類別。

(繼承來源 Style)
Site

取得或設定 ComponentISite

(繼承來源 Component)
VerticalAlign

取得或設定儲存格中內容的垂直對齊。

ViewState

取得保存樣式項目的狀態包。

(繼承來源 Style)
Width

取得或設定 Web 伺服器控制項的寬度。

(繼承來源 Style)
Wrap

取得或設定值,指出儲存格內容是否在儲存格中換行。

方法

AddAttributesToRender(HtmlTextWriter)

將需要呈現的 HTML 屬性和樣式加入至指定的 HtmlTextWriter 中。 這個方法主要由控制項開發人員使用。

(繼承來源 Style)
AddAttributesToRender(HtmlTextWriter, WebControl)

將水平對齊、垂直對齊和換行的相關資訊加入要呈現的屬性清單。

CopyFrom(Style)

將指定之 Style 的非空白樣式屬性,複製至呼叫這個方法的 TableItemStyle 類別執行個體。

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 Component)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
FillStyleAttributes(CssStyleCollection, IUrlResolutionService)

將指定物件的樣式屬性加入 CssStyleCollection 物件中。

(繼承來源 Style)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已過時。

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。

(繼承來源 Component)
GetStyleAttributes(IUrlResolutionService)

擷取指定 CssStyleCollection 實作物件的 IUrlResolutionService 物件。

(繼承來源 Style)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
InitializeLifetimeService()
已過時。

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
LoadViewState(Object)

載入先前儲存的狀態。

(繼承來源 Style)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
MergeWith(Style)

將指定的 Style 的樣式屬性與呼叫這個方法的 TableItemStyle 類別的執行個體組合在一起。

Reset()

將所有已定義樣式項目從樣式中移除。

SaveViewState()

保護的 (Protected) 方法。 儲存叫用 TrackViewState() 方法之後,任何已變更的狀態。

(繼承來源 Style)
SetBit(Int32)

保護的內部方法。 設定內部位元遮罩欄位,表示儲存在狀態包中的樣式屬性。

(繼承來源 Style)
SetDirty()

標記 Style,以便將其狀態記錄在檢視狀態中。

(繼承來源 Style)
ToString()

傳回代表目前物件的字串。

(繼承來源 Style)
TrackViewState()

保護的 (Protected) 方法。 在控制項上標記追蹤狀態變更的開頭。 任何在追蹤開始後的變更都會被追蹤,並儲存成控制項檢視狀態的一部分。

(繼承來源 Style)

事件

Disposed

Dispose() 方法的呼叫處置元件時,就會發生。

(繼承來源 Component)

明確介面實作

IStateManager.IsTrackingViewState

取得值,指出伺服器控制項是否正在追蹤其檢視狀態變更。

(繼承來源 Style)
IStateManager.LoadViewState(Object)

載入先前儲存的狀態。

(繼承來源 Style)
IStateManager.SaveViewState()

傳回包含狀態變更的物件。

(繼承來源 Style)
IStateManager.TrackViewState()

啟動追蹤狀態的變更。

(繼承來源 Style)

適用於

另請參閱