我的动态DataList和Repeater模版
Imports System.Web.UI
Public Class MyTemplate
Implements ITemplate
Shared itemcount As Integer = 0
Dim TemplateType As ListItemType
Dim ItemName As String
Sub New(ByVal type As ListItemType)
TemplateType = type
End Sub
Sub New(ByVal type As ListItemType, ByVal _ItemName As String)
ItemName = _ItemName
TemplateType = type
End Sub
Sub InstantiateIn(ByVal container As Control) _
Implements ITemplate.InstantiateIn
Dim lc As New Literal
Select Case TemplateType
Case ListItemType.Header
lc.Text = "<TABLE border=1 style='BORDER-COLLAPSE: collapse'><TR><TD class=GridHead>Items</TD></TR>"
Case ListItemType.Item
lc.Text = "<TR><TD align=center>"
AddHandler lc.DataBinding, AddressOf TemplateControl_DataBinding
Case ListItemType.AlternatingItem
lc.Text = "<TR><TD align=center bgcolor=lightblue>"
AddHandler lc.DataBinding, AddressOf TemplateControl_DataBinding
Case ListItemType.Footer
lc.Text = "</TABLE>"
End Select
container.Controls.Add(lc)
itemcount += 1
End Sub
Private Sub TemplateControl_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lc As Literal
lc = CType(sender, Literal)
Dim container As DataListItem
container = CType(lc.NamingContainer, DataListItem)
lc.Text = DataBinder.Eval(container.DataItem, ItemName)
lc.Text &= "</TD></TR>"
End Sub
End Class