TableItemStyle 类

定义

标识作为 TableRowTableCell 呈现的控件元素的样式属性。Represents the style properties for an element of a control that renders as a TableRow or TableCell.

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将对象应用于每一行。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)
    {
//<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>

注解

类表示TableRow作为或TableCell呈现的控件元素的样式属性。 TableItemStyleThe TableItemStyle class represents the style properties for an element of a control that renders as a TableRow or TableCell. 您可以分别通过设置HorizontalAlignVerticalAlign属性来控制表项中内容的垂直和水平对齐方式。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. 通过设置Wrap属性, 还可以指定在到达单元格的末尾时, 该单元格的内容是否自动继续。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.

此类提供了一些方法, 这些方法可用于为Table控件中的项创建样式。This class provides methods that are useful for creating a style for an item in the Table control. 您可以使用CopyFromMergeWith方法, 通过调用方法的的实例TableItemStyle , 复制或TableItemStyle合并另一个的样式属性。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.

构造函数

TableItemStyle()

用默认值创建 TableItemStyle 类的新实例。Creates a new instance of the TableItemStyle class using default values.

TableItemStyle(StateBag)

用指定的状态袋创建 TableItemStyle 类的新实例。Creates a new instance of the TableItemStyle class with the specified state bag.

属性

BackColor

获取或设置 Web 服务器控件的背景色。Gets or sets the background color of the Web server control.

(继承自 Style)
BorderColor

获取或设置 Web 服务器控件的边框颜色。Gets or sets the border color of the Web server control.

(继承自 Style)
BorderStyle

获取或设置 Web 服务器控件的边框样式。Gets or sets the border style of the Web server control.

(继承自 Style)
BorderWidth

获取或设置 Web 服务器控件的边框宽度。Gets or sets the border width of the Web server control.

(继承自 Style)
CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(继承自 Component)
CssClass

获取或设置由 Web 服务器控件在客户端呈现的级联样式表 (CSS) 类。Gets or sets the cascading style sheet (CSS) class rendered by the Web server control on the client.

(继承自 Style)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
Font

获取与 Web 服务器控件关联的字体属性。Gets the font properties associated with the Web server control.

(继承自 Style)
ForeColor

获取或设置 Web 服务器控件的前景色(通常是文本颜色)。Gets or sets the foreground color (typically the color of the text) of the Web server control.

(继承自 Style)
Height

获取或设置 Web 服务器控件的高度。Gets or sets the height of the Web server control.

(继承自 Style)
HorizontalAlign

获取或设置单元格内容的水平对齐方式。Gets or sets the horizontal alignment of the contents in a cell.

IsEmpty

保护属性。A protected property. 获取一个值,该值指示是否已在状态袋中定义任何样式元素。Gets a value indicating whether any style elements have been defined in the state bag.

(继承自 Style)
IsTrackingViewState

返回一个值,该值指示状态袋中是否有任何已定义的样式元素。Returns a value indicating whether any style elements have been defined in the state bag.

(继承自 Style)
RegisteredCssClass

获取已向控件注册的级联样式表 (CSS) 类。Gets the cascading style sheet (CSS) class that is registered with the control.

(继承自 Style)
Site

获取或设置 ISiteComponentGets or sets the ISite of the Component.

(继承自 Component)
VerticalAlign

获取或设置单元格内容的垂直对齐方式。Gets or sets the vertical alignment of the contents in a cell.

ViewState

获取保存样式元素的状态袋。Gets the state bag that holds the style elements.

(继承自 Style)
Width

获取或设置 Web 服务器控件的宽度。Gets or sets the width of the Web server control.

(继承自 Style)
Wrap

获取或设置一个值,该值指示单元格的内容在单元格中是否换行。Gets or sets a value indicating whether the contents of a cell wrap in the cell.

方法

AddAttributesToRender(HtmlTextWriter)

将需要呈现的 HTML 特性和样式添加到指定的 HtmlTextWriter 中。Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter. 此方法主要由控件开发人员使用。This method is primarily used by control developers.

(继承自 Style)
AddAttributesToRender(HtmlTextWriter, WebControl)

将有关水平对齐方式、垂直对齐方式和包装的信息添加到要呈现的特性列表中。Adds information about horizontal alignment, vertical alignment, and wrap to the list of attributes to render.

CopyFrom(Style)

将指定 Style 的非空样式属性复制到从中调用此方法的 TableItemStyle 类的实例中。Duplicates the non-empty style properties of the specified Style into the instance of the TableItemStyle class that this method is called from.

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

释放 Component 使用的所有资源。Releases all resources used by the Component.

(继承自 Component)
Dispose(Boolean)

释放 Component 使用的非托管资源,并选择性地释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(继承自 Component)
Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FillStyleAttributes(CssStyleCollection, IUrlResolutionService)

将指定对象的样式属性添加到 CssStyleCollection 对象。Adds the specified object's style properties to a CssStyleCollection object.

(继承自 Style)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetStyleAttributes(IUrlResolutionService)

检索实现了 CssStyleCollection 的指定对象的 IUrlResolutionService 对象。Retrieves the CssStyleCollection object for the specified IUrlResolutionService-implemented object.

(继承自 Style)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
LoadViewState(Object)

加载以前保存的状态。Loads the previously saved state.

(继承自 Style)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
MergeWith(Style)

将指定 Style 的样式属性与从中调用此方法的 TableItemStyle 类的实例组合。Combines the style properties of the specified Style into the instance of the TableItemStyle class that this method is called from.

Reset()

从样式中移除任何已定义的样式元素。Removes any defined style elements from the style.

SaveViewState()

受保护的方法。A protected method. 保存在调用 TrackViewState() 方法后已修改的任何状态。Saves any state that has been modified after the TrackViewState() method was invoked.

(继承自 Style)
SetBit(Int32)

受保护的内部方法。A protected internal method. 设置一个内部位屏蔽字段以指示存储在状态袋中的样式属性。Sets an internal bitmask field that indicates the style properties that are stored in the state bag.

(继承自 Style)
SetDirty()

标记 Style 以便在视图状态中记录其状态。Marks the Style so that its state will be recorded in view state.

(继承自 Style)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Style)
TrackViewState()

受保护的方法。A protected method. 标记跟踪控件状态更改的起始点。Marks the beginning for tracking state changes on the control. 跟踪开始之后所做的任何更改都将被跟踪并保存到控件视图状态中。Any changes made after tracking has begun will be tracked and saved as part of the control view state.

(继承自 Style)

事件

Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)

显式接口实现

IStateManager.IsTrackingViewState

获取一个值,该值指示服务器控件是否在跟踪其视图状态更改。Gets a value that indicates whether a server control is tracking its view state changes.

(继承自 Style)
IStateManager.LoadViewState(Object)

加载以前保存的状态。Loads the previously saved state.

(继承自 Style)
IStateManager.SaveViewState()

返回包含状态更改的对象。Returns the object containing state changes.

(继承自 Style)
IStateManager.TrackViewState()

开始跟踪状态更改。Starts tracking state changes.

(继承自 Style)

适用于

另请参阅