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
databinder.eval.
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,
"textbox")
DLsection.HeaderTemplate = New mytemplate(ListItemType.Header,
"header")
DLsection.ItemTemplate = New mytemplate(ListItemType.Item,
"image")
DLsection.DataSource = DSlinkdata.Tables(inttablecount)
DLsection.DataBind()
Page.Controls(1).Controls.Add(DLsection)
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
TemplateControl_DataBinding
container.Controls.Add(lc)
Case ListItemType.Item
tb.Text = "test"
myim.ImageUrl = "images/help.gif"
container.Controls.Add(myim)
container.Controls.Add(tb)
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.