⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compositetablecontrol.cs

📁 东软内部材料(四)asp等相关的教学案例 
💻 CS
字号:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WroxControls 
{

	public class Simple : Control, INamingContainer
	{
		 protected override void LoadViewState(object savedState)
		 {
			throw new Exception("called 2");
		 }

//		protected override object SaveViewState()
//		{
//			throw new Exception("called");
//		}
	}

   public class CompositeTableControl : Control, INamingContainer
											        // Step 3
   {
      Table _table;  // Make table a member so we can access it at any point

		protected override void OnInit(EventArgs e)
		{
		}

      protected override void CreateChildControls()
      {
         LiteralControl text;

			Controls.Add( new Simple() );

	Context.Trace.Write("CompositeTableControl","CreateChildControls()");

         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++) {

				   TextBox textbox;
			      textbox = new TextBox();

					// Step 2 - don't set the text property during postback

					if ( Page.IsPostBack == false )
	               textbox.Text = "Row: " + x + " Cell: " + y;

               cell = new TableCell();
               row.Cells.Add(cell);

               cell.Controls.Add(textbox);

               }
           }
       }
   }
};

⌨️ 快捷键说明

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