compositetablecontrol_step1.cs

来自「Professional ASP.NET source code」· CS 代码 · 共 54 行

CS
54
字号
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WroxControls 
{
   public class CompositeTableControl : Control 
   {
      Table _table;  // Make table a member so we can access it at any point
 
      protected override void CreateChildControls()
      {
         LiteralControl text;

         text = new LiteralControl(
                      "<h1>ASP.NET Control Development in C#</h1>");
         Controls.Add(text);

         TableRow row;
         TableCell cell;

         // Create a table and set a 2 pixel border

         _table = new Table();
         _table.BorderWidth = 2;

         Controls.Add(_table);

         // Add 10 row each with 5 cells 

         for(int x = 0; x < 10; x++) {
            // Create a row and add it to the table
         
            row = new TableRow();
            _table.Rows.Add(row);

            // Create a cell that contains the text

            for(int y = 0; y < 5; y++) {

               text = new LiteralControl("Row: " + x + " Cell: " + y);

               cell = new TableCell();
               cell.Controls.Add(text);

               row.Cells.Add(cell);
               }
           }
       }
   }
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?