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
