本文整理汇总了VB.NET中System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls方法的典型用法代码示例。如果您正苦于以下问题:VB.NET CompositeDataBoundControl.CreateChildControls方法的具体用法?VB.NET CompositeDataBoundControl.CreateChildControls怎么用?VB.NET CompositeDataBoundControl.CreateChildControls使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.CompositeDataBoundControl
的用法示例。
在下文中一共展示了CompositeDataBoundControl.CreateChildControls方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: New
' 导入命名空间
Imports System.Collections
Imports System.Data.Common
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace Samples.AspNet.VB
Public Class SimpleSpreadsheetControl
Inherits CompositeDataBoundControl
Protected table As New Table()
Public Overridable ReadOnly Property Rows() As TableRowCollection
Get
Return table.Rows
End Get
End Property
Protected Overrides Function CreateChildControls(ByVal dataSource As IEnumerable, ByVal dataBinding As Boolean) As Integer
Dim count As Integer = 0
' If dataSource is not Nothing, iterate through it and
' extract each element from it as a row, then
' create a SimpleSpreadsheetRow and add it to the
' rows collection.
If Not (dataSource Is Nothing) Then
Dim row As SimpleSpreadsheetRow
Dim e As IEnumerator = dataSource.GetEnumerator()
While e.MoveNext()
Dim datarow As Object = e.Current
row = New SimpleSpreadsheetRow(count, datarow)
Me.Rows.Add(row)
count += 1
End While
Controls.Add(table)
End If
Return count
End Function 'CreateChildControls
End Class
Public Class SimpleSpreadsheetRow
Inherits TableRow
Implements IDataItemContainer
Private dataObj As Object
Private _itemIndex As Integer
Public Sub New(ByVal itemIndex As Integer, ByVal o As Object)
dataObj = o
_itemIndex = itemIndex
End Sub
Public Overridable ReadOnly Property Data() As Object
Get
Return dataObj
End Get
End Property
ReadOnly Property DataItem() As Object Implements IDataItemContainer.DataItem
Get
Return Data
End Get
End Property
ReadOnly Property DataItemIndex() As Integer Implements IDataItemContainer.DataItemIndex
Get
Return _itemIndex
End Get
End Property
ReadOnly Property DisplayIndex() As Integer Implements IDataItemContainer.DisplayIndex
Get
Return _itemIndex
End Get
End Property
Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
If Not (Data Is Nothing) Then
If TypeOf Data Is System.Data.Common.DbDataRecord Then
Dim temp As DbDataRecord = CType(Data, DbDataRecord)
Dim i As Integer
While i < temp.FieldCount
writer.Write("<TD>")
writer.Write(temp.GetValue(i).ToString())
writer.Write("</TD>")
i += 1
End While
Else
writer.Write(("<TD>" + Data.ToString() + "</TD>"))
End If
Else
writer.Write("<TD>This is a test</TD>")
End If
End Sub
End Class
End Namespace
开发者ID:VB.NET开发者,项目名称:System.Web.UI.WebControls,代码行数:104,代码来源:CompositeDataBoundControl.CreateChildControls