日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Table控件使用示例

 醉人說夢 2014-08-08
代碼
復(fù)制代碼
<%@ 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>
復(fù)制代碼

 

Table控件允許您生成 HTML 表并以直接方式指定其屬性。可以用給定的靜態(tài)內(nèi)容在設(shè)計時生成表,但 Table Web 服務(wù)器控件的威力通常在用動態(tài)內(nèi)容以編程方式生成表時才會體現(xiàn)出來。

值得注意的是,以編程方式對表行或單元格所做的任何添加或修改不在向服務(wù)器的發(fā)送間保持。這是因為表行和單元格本身就是控件,而不是Table 控件的屬性。要保持對表所做的任何更改,必須在每次回送后重新構(gòu)造行和單元格。實際上,如果需要進行實質(zhì)性的修改,建議使用 DataList、DataGrid 或 GridView 控件,而不是Table 控件。因此,該Table 類主要由控件開發(fā)人員使用。

 

 

將在每個單元格中顯示靜態(tài)文本和 Hyperlink 控件。Hyperlink 控件定位到一個模擬的 URL,傳遞一個模擬產(chǎn)品 ID。由于該示例混合了靜態(tài)文本和控件,因此靜態(tài)文本Literal 對象的形式實現(xiàn),像Hyperlink 控件一樣添加到單元格的Controls 集合中。

 

復(fù)制代碼
代碼
Protected void Button1_Click (object sender, System.EventArgs e)
{
   // 總行數(shù).
   int rowCnt;
   // 當前行號.
   int rowCtr;
   // 每行列數(shù).
   int cellCtr;
   // 當前列號.
   int cellCnt;

   rowCnt = int.Parse(TextBox1.Text);
   cellCnt = int.Parse(TextBox2.Text);

   for(rowCtr=1; rowCtr <= rowCnt; rowCtr++) {
      // Create a new row and add it to the table.
      TableRow tRow = new TableRow();
      Table1.Rows.Add(tRow);
      for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++) {
         // Create a new cell and add it to the row.
         TableCell tCell = new TableCell();
         tRow.Cells.Add(tCell);               
         // Mock up a product ID.
         string prodID = rowCtr + "_" + cellCtr;

         // Add a literal text as control.
         tCell.Controls.Add(new LiteralControl("Buy: "));
         // Create a Hyperlink Web server control and add it to the cell.
         System.Web.UI.WebControls.HyperLink h = new HyperLink();
         h.Text = rowCtr + ":" + cellCtr;
         h.NavigateUrl = "http://www.microsoft.com/net";
         tCell.Controls.Add(h);
      }
   }
}
復(fù)制代碼

 

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多