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

相关文章:

  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-02-27
  • 2021-09-21
猜你喜欢
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
  • 2021-10-21
  • 2021-06-30
  • 2021-09-03
  • 2022-12-23
相关资源
相似解决方案