[Posting] Use Asp.net to dynamically create datalist and inherit itemplate

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.