Dynamically create DataList using ASP.NET

xiaoxiao2021-03-06  100

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) Templattype = 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 = "

Items "Case ListItemType.Item lc.Text ="
Item number: " '& itemcount.ToString &" "AddHandler lc.DataBinding, AddressOf TemplateControl_Databinding Case ListItemType.AlternatingItem lc.Text = "
Item Number:" _ & itemcount.tostring & "Case ListItemType.Footer lc.text =" "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. N AmingContainer, DatalistItem) lc.text & = dataBinder.eval (Container.DataItem, "Text") lc.text & = " " End Subend Class

转载请注明原文地址:https://www.9cbs.com/read-105596.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.045, SQL: 9