Web服务器控件:TableRow控件

http://www.itjxue.com  2015-07-17 01:59  来源:未知  点击次数: 

阅读此文请先查看IT教学网的:ASP.NET入门教程:Web服务器控件,简单讲述了Web服务器控件的使用方法。

定义和用法

TableRow 控件与 TableCell 控件和 Table 控件一起使用,来创建表格中的行。表示 Table 控件中的行并允许您以编程方式对其进行操作。

提示:表格的行存储在 Table 控件中的 Rows 集合中。

属性

属性 描述 .NET
Cells TableCell 对象的集合,这些对象表示 Table 控件中的行的单元格。  
HorizontalAlign 表格行中内容的水平对齐方式。 1.0
TableSection Table 控件中 TableRow 对象的位置。 2.0
VerticalAlign 行内容的垂直对齐方式。 1.0

Web 控件标准属性

AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, 
CssClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled, 
SkinID, Style, TabIndex, ToolTip, Width

控件标准属性

AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls, 
EnableTheming, EnableViewState, ID, NamingContainer, Page, Parent, Site, 
TemplateControl, TemplateSourceDirectory, UniqueID, Visible

语法

<asp:TableRow
    AccessKey="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CssClass="string"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    HorizontalAlign="NotSet|Left|Center|Right|Justify"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    TableSection="TableHeader|TableBody|TableFooter"
    ToolTip="string"
    VerticalAlign="NotSet|Top|Middle|Bottom"
    Visible="True|False"
    Width="size"
>
        <asp:TableCell
            AccessKey="string"
            AssociatedHeaderCellID="string"
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            ColumnSpan="integer"
            CssClass="string"
            Enabled="True|False"
            EnableTheming="True|False"
            EnableViewState="True|False"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|
                X-Small|Small|Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalAlign="NotSet|Left|Center|Right|Justify"
            ID="string"
            OnDataBinding="DataBinding event handler"
            OnDisposed="Disposed event handler"
            OnInit="Init event handler"
            OnLoad="Load event handler"
            OnPreRender="PreRender event handler"
            OnUnload="Unload event handler"
            RowSpan="integer"
            runat="server"
            SkinID="string"
            Style="string"
            TabIndex="integer"
            Text="string"
            ToolTip="string"
            VerticalAlign="NotSet|Top|Middle|Bottom"
            Visible="True|False"
            Width="size"
            Wrap="True|False"
        />
        <asp:TableHeaderCell
            AbbreviatedText="string"
            AccessKey="string"
            AssociatedHeaderCellID="string"
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            CategoryText="string"
            ColumnSpan="integer"
            CssClass="string"
            Enabled="True|False"
            EnableTheming="True|False"
            EnableViewState="True|False"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|
                X-Small|Small|Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalAlign="NotSet|Left|Center|Right|Justify"
            ID="string"
            OnDataBinding="DataBinding event handler"
            OnDisposed="Disposed event handler"
            OnInit="Init event handler"
            OnLoad="Load event handler"
            OnPreRender="PreRender event handler"
            OnUnload="Unload event handler"
            RowSpan="integer"
            runat="server"
            Scope="NotSet|Row|Column"
            SkinID="string"
            Style="string"
            TabIndex="integer"
            Text="string"
            ToolTip="string"
            VerticalAlign="NotSet|Top|Middle|Bottom"
            Visible="True|False"
            Width="size"
            Wrap="True|False"
        />
</asp:TableRow>

备注:TableRow 类的实例表示 Table 控件中的行。表中的行存储在 Table 控件的 Rows 集合中。

此类使您可以控制行内容的显示方式。设置 HorizontalAlign 和 VerticalAlign 属性可以分别指定行中内容的水平和垂直对齐方式。

行中的单元格(由 TableCell 类的实例表示)存储在表示该行的 TableRow 的 Cells 集合中。使用 Cells 集合可以通过编程方式管理行中的单元格。

示例

下面的示例演示如何使用 TableRow 对象向 Table 控件添加行。

Visual Basic

<%@ Page language="VB" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<html>
    <head>
        <script runat="server">
            Private Sub Page_Load(sender As Object, e As System.EventArgs)
                ' 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)
                ' Create more rows for the table.
                Dim i As Integer
                For i = 2 To 9
                    Dim tempRow As New TableRow()
                    Dim j As Integer
                    For j = 0 To 2
                        Dim tempCell As New TableCell()
                        tempCell.Text = "(" & i & "," & j & ")"
                        tempRow.Cells.Add(tempCell)
                    Next j
                    Table1.Rows.Add(tempRow)
                Next i
                ' Apply the TableItemStyle to all rows in the table.
                Dim r As TableRow
                For Each r In  Table1.Rows
                    Dim c As TableCell
                    For Each c In  r.Cells
                        c.ApplyStyle(tableStyle)
                    Next c
                Next r
                ' 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)
            End Sub
        </script>
    </head>
    <body>
        <form runat="server">
            <h1>TableCell Example</h1>
            <asp:table id="Table1" runat="server" CellPadding="3" CellSpacing="3">
                <asp:TableRow>
                    <asp:TableCell Text="(0,0)"></asp:TableCell>
                    <asp:TableCell Text="(0,1)"></asp:TableCell>
                    <asp:TableCell Text="(0,2)"></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell Text="(1,0)"></asp:TableCell>
                    <asp:TableCell Text="(1,1)"></asp:TableCell>
                    <asp:TableCell Text="(1,2)"></asp:TableCell>
                </asp:TableRow>
            </asp:table>
        </form>
    </body>
</html>

C#

<%@ Page language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<html>
    <head>
        <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 i = 2; i < 10; i++)
                {
                    TableRow tempRow = new TableRow();
                    for (int j = 0; j < 3; j++)
                    {
                        TableCell tempCell = new TableCell();
                        tempCell.Text = "(" + i + "," + j + ")";
                        tempRow.Cells.Add(tempCell);
                    }
                    Table1.Rows.Add(tempRow);
                }
                // Apply the TableItemStyle to all rows in the table.
                foreach (TableRow r in Table1.Rows)
                    foreach (TableCell c in r.Cells)
                        c.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>
    </head>
    <body>
        <form runat="server">
            <h1>TableCell Example</h1>
            <asp:table id="Table1" runat="server" CellPadding="3" CellSpacing="3">
                <asp:TableRow>
                    <asp:TableCell Text="(0,0)"></asp:TableCell>
                    <asp:TableCell Text="(0,1)"></asp:TableCell>
                    <asp:TableCell Text="(0,2)"></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell Text="(1,0)"></asp:TableCell>
                    <asp:TableCell Text="(1,1)"></asp:TableCell>
                    <asp:TableCell Text="(1,2)"></asp:TableCell>
                </asp:TableRow>
            </asp:table>
        </form>
    </body>
</html>

(责任编辑:IT教学网)

更多

推荐ASP.NET教程文章