📄 dictionarylister2.vb
字号:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Collections
Imports System.Web.UI.WebControls
Namespace WroxControls
' Naming container for template items
Public Class CollectionItem2
Inherits WebControl
Implements INamingContainer
Dim _dataitem As Object
Public ReadOnly Property DataItem As Object
Get
Return _dataitem
End Get
End Property
Public Sub New (value As Object)
_dataitem = value
End Sub
End Class
Public Class ICollectionLister2
Inherits WebControl
Implements INamingContainer
' Step 3
' The data source the control will enumerate
Dim _datasource As ICollection
Public Property DataSource As ICollection
Get
Return _datasource
End Get
Set
_datasource = value
End Set
End Property
' The template used for the header
Dim _headingStyle As ITemplate
<TemplateContainer(GetType(ICollectionLister2))> _
Public Property HeadingStyle As ITemplate
Get
Return _headingStyle
End Get
Set
_headingStyle = value
End Set
End Property
' The template used for the item
Dim _itemStyle As ITemplate
<TemplateContainer(GetType(CollectionItem2))> _
Public Property ItemStyle As ITemplate
Get
Return _itemStyle
End Get
Set
_itemStyle = value
End Set
End Property
' Create the child control hierarchy from viewstate only
Protected Overrides Sub CreateChildControls()
Dim iCount As Integer = 0
Dim i As Integer
Dim item As CollectionItem2
If Not (_headingStyle Is Nothing) Then
_headingStyle.InstantiateIn( Me )
End if
iCount = ViewState("count")
For i = 0 To iCount - 1
If Not (_itemStyle Is Nothing)
item = new CollectionItem2( Nothing )
_itemStyle.InstantiateIn( item )
Controls.Add( item )
End if
Next
End Sub
' Create control hierarchy with the data source
Protected Overrides Sub OnDataBinding( args As EventArgs )
MyBase.OnDataBinding(args)
If _datasource Is Nothing Then
Throw New Exception("Control requires a data source")
End If
ClearChildViewState()
Controls.Clear()
' Clear all controls and state
Dim e As IEnumerator
Dim iCount As Integer = 0
If Not (_headingStyle Is Nothing) Then
_headingStyle.InstantiateIn( Me )
End If
e = _datasource.GetEnumerator()
Dim item As CollectionItem2
While e.MoveNext()
If Not (_itemStyle Is Nothing) Then
item = New CollectionItem2( e.Current )
_itemStyle.InstantiateIn( item )
Controls.Add( item )
iCount += 1
End If
End While
' Remember the number of controls, so we can recreate the
' same controls, without the data source.
ViewState("count") = iCount
' stop CreateChildControls() being called again
ChildControlsCreated = true
' Ensure view state is being tracked
TrackViewState()
End Sub
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -