<%@ 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>

參考:
http://msdn.microsoft.com/zh-tw/library/tk1zfd2e(VS.80).aspx
http://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.webcontrol.borderwidth(v=VS.80).aspx

arrow
arrow
    全站熱搜

    Empty 發表在 痞客邦 留言(0) 人氣()