Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load
'Put user code to initialize the page here
Dim DL as new datalist
DL. headertemplate = new createdl (listitemtype. header)
DL. itemtemplate = new createdl (listitemtype. item)
DL. alternatingitemtemplate = new createdl (listitemtype. alternatingitem)
DL. footertemplate = new createdl (listitemtype. footer)
Dim D as new data
DL. datasource = D. gettree
DL. databind ()
Div1.controls. Add (DL)
End sub
Public class createdl
Implements itemplate
Shared itemcount as integer = 0
Dim templatetype as listitemtype
Sub new (byval type as listitemtype)
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> <tr> <TH> items </Th> </tr>"
Case listitemtype. Item
LC. Text = "<tr> <TD> item number:" '& itemcount. tostring & "</TD> </tr>"
Addhandler LC. databinding, addressof templatecontrol_databinding
Case listitemtype. alternatingitem
LC. Text = "<tr> <TD bgcolor = lightblue> item number :"_
& Itemcount. tostring & "</TD> </tr>"
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, "text ")
LC. Text & = "</TD> </tr>"
End sub
End Class