本文整理匯總了VB.NET中System.Web.UI.IDataItemContainer接口的典型用法代碼示例。如果您正苦於以下問題:VB.NET IDataItemContainer接口的具體用法?VB.NET IDataItemContainer怎麽用?VB.NET IDataItemContainer使用的例子?那麽, 這裏精選的接口代碼示例或許可以為您提供幫助。
在下文中一共展示了IDataItemContainer接口的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