compositetablecontrol.vb

来自「This is a book about vb.you could learn 」· VB 代码 · 共 95 行

VB
95
字号
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace WroxControls 

	Public Class Simple
			Inherits Control
			Implements INamingContainer
	
		 Protected Overrides Sub LoadViewState(savedState As Object)
		 
			throw new Exception("called 2")
		 
		 End Sub

'		Protected Overrides Function SaveViewState() As Object
'			Throw New Exception("called")
'		End Function
	
	End Class


	' Step 3
	Public Class CompositeTableControl
			Inherits Control
			Implements INamingContainer
	
		Dim _table As Table 		' Make table a member so we can access it at any point

		Protected Overrides Sub OnInit(e As EventArgs)
		End Sub


		Protected Overrides Sub CreateChildControls()
		
			Dim text As LiteralControl

			Controls.Add( new Simple() )

			Context.Trace.Write("CompositeTableControl","CreateChildControls()")
			
			text = new LiteralControl("<h1>ASP.NET Control Development in C#</h1>")
			Controls.Add(text)


			Dim row As TableRow
			Dim cell As TableCell

			' Create a table and set a 2 pixel border

			_table = new Table()
			_table.BorderWidth = New Unit(2)

			Controls.Add(_table)

			' Add 10 row each with 5 cells 

			Dim x As Integer
			For x = 0 To 9
				' Create a row and add it to the table

				row = new TableRow()
				_table.Rows.Add(row)

				' Create a cell that contains the text

				Dim y As Integer
				For y = 0 To 4

					Dim textbox As TextBox
					textbox = new TextBox()

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

					If Page.IsPostBack = False Then
						textbox.Text = "Row: " & x & " Cell: " & y
					End If

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

					cell.Controls.Add(textbox)

				Next
			Next
		
		End Sub
	
	End Class

End Namespace

⌨️ 快捷键说明

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