欢迎光临
我们一直在努力

利用Asp.net 动态创建DataList-ASP教程,ASP应用

建站超值云服务器,限时71元/月

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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 利用Asp.net 动态创建DataList-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章