程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> Web服務器控件:TableRow控件

Web服務器控件:TableRow控件

編輯:關於.NET

定義和用法

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"
    BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">        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"
   
    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"
            BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                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"
           
            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"
            BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                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"
           
            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>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved