📄 compositetablecontrol.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 + -