By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,810 Members | 783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,810 IT Pros & Developers. It's quick & easy.

Dynamic Templates for a datalist

P: n/a
Hi Everybody

I'm hoping that someone can help me as I'm totally stumped. I am
trying to populate a datalist using the dynamic templates. I have used
the example on Microsofts site, I can't get the data to bind using the
Here is my code...

on the aspx page

Public Sub createdatalist(ByVal conn, ByVal DGcount)
Dim DLsection As New DataList

DLsection.BorderWidth = Unit.Pixel(2)
DLsection.CellPadding = 10
DLsection.GridLines = GridLines.Both
DLsection.BorderColor = Color.Blue
DLsection.ShowHeader = True
DLsection.SelectedItemStyle.BackColor = Color.Yellow
DLsection.ID = "DL" + CStr(DGcount)
DLsection.EnableViewState = True
DLsection.RepeatDirection = RepeatDirection.Horizontal
DLsection.RepeatLayout = RepeatLayout.Table
DLsection.RepeatColumns = 2
DLsection.CellSpacing = 5

DLsection.ItemTemplate = New mytemplate(ListItemType.Item,
DLsection.HeaderTemplate = New mytemplate(ListItemType.Header,
DLsection.ItemTemplate = New mytemplate(ListItemType.Item,

DLsection.DataSource = DSlinkdata.Tables(inttablecount)

End Sub

in the class

Public Class mytemplate

Implements ITemplate
Dim templateType As ListItemType
Dim columnName As String

Sub New(ByVal type As ListItemType, ByVal ColName As String)
templateType = type
columnName = ColName
End Sub
Sub InstantiateIn(ByVal container As Control) _
Implements ITemplate.InstantiateIn
Dim lc As New TextBox
Dim tb As New TextBox
Dim tb1 As New TextBox
Dim myim As New Image

Select Case templateType

Case ListItemType.Header
lc.Text = ""
AddHandler lc.DataBinding, AddressOf

Case ListItemType.Item
tb.Text = "test"
myim.ImageUrl = "images/help.gif"
End Select
End Sub

Private Sub TemplateControl_DataBinding(ByVal sender As Object,
ByVal e As System.EventArgs)

Dim lc As TextBox
lc = CType(sender, TextBox)
Dim container As DataListItem
container = CType(lc.NamingContainer, DataListItem)

lc.Text = DataBinder.Eval(container.DataItem, "med_sect_name")

End Sub

Please, please, plase help...this is driving me mad.

Dec 2 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.