Use Asp.net to dynamically create DataList-VB

Source: Internet
Author: User

Private Sub Page_Load (ByVal sender As System. object, ByVal e As System. eventArgs) Handles MyBase. load <br/> 'put user code to initialize the page here <br/> Dim dl As New DataList <br/> dl. headerTemplate = New CreateDL (ListItemType. header) <br/> dl. itemTemplate = New CreateDL (ListItemType. item) <br/> dl. alternatingItemTemplate = New CreateDL (ListItemType. alternatingItem) <br/> dl. footerTemplate = New CreateDL (ListItemType. footer) <br/> Dim d As New Data <br/> dl. dataSource = d. getTree <br/> dl. dataBind () <br/> div1.Controls. add (dl) </p> <p> End Sub </p> <p> Public Class CreateDL <br/> Implements ITemplate <br/> Shared itemcount As Integer = 0 <br/> Dim templateType As ListItemType </p> <p> Sub New (ByVal type As ListItemType) <br/> TemplateType = type <br/> End Sub </p> <p> Sub InstantiateIn (ByVal container As Control) Implements ITemplate. instantiateIn <br/> Dim lc As New Literal <br/> Select Case TemplateType <br/> Case ListItemType. header <br/> lc. text = "<TABLE border = 1> <TR> <TH> Items </TH> </TR>" <br/> Case ListItemType. item <br/> lc. text = "<TR> <TD> Item number:" '& itemcount. toString & "</TD> </TR>" <br/> AddHandler lc. dataBinding, AddressOf TemplateControl_Databinding <br/> Case ListItemType. alternatingItem <br/> lc. text = "<TR> <TD bgcolor = lightblue> Item number:" _ <br/> & itemcount. toString & "</TD> </TR>" <br/> Case ListItemType. footer <br/> lc. text = "</TABLE>" <br/> End Select <br/> container. controls. add (lc) <br/> itemcount + = 1 <br/> End Sub <br/> Private Sub TemplateControl_DataBinding (ByVal sender As Object, _ <br/> ByVal e As System. eventArgs) <br/> Dim lc As Literal <br/> lc = CType (sender, Literal) <br/> Dim container As DataListItem <br/> container = CType (lc. namingContainer, DataListItem) <br/> lc. text & = DataBinder. eval (container. dataItem, "text") <br/> lc. text & = "</TD> </TR>" <br/> End Sub </p> <p> End Class </p> <p> This article is from the CSDN blog, reprinted please indicate the source: http://blog.csdn.net/goody9807/archive/2004/10/16/138820.aspx

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.