473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Dynamic Templates for a datalist

KT
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.

Dec 2 '05 #1
0 1216

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Leslaw Bieniasz | last post by:
Cracow, 20.10.2004 Hello, As far as I understand, the generic programming basically consists in using templates for achieving a static polymorphism of the various code fragments, and their...
4
by: Yan Wang | last post by:
Hi!: I encounter this problem when I do some tests: I have one user control with datalist in it. The ID for datalist is "dlTest". Then in this control code behind class, I declare a protected...
1
by: Scott Schluer | last post by:
Hello, I've got myself a small problem and I'm hoping someone can help. I have a DataList called dlProducts (displays products from a database). Within the <ItemTemplate> container of the...
2
by: stb | last post by:
Hi. Is it possible to write inline Templates for a DataList dynamically in the HTML code, based on the DataSet that is bound to the DataList? Anyone know how?
3
by: mbailey | last post by:
Hello- I am failry new to asp.net but have been coding in general for a while. I have a datalist whos templates are built on the fly. In the Page_Init sub, based on a certain value, certain...
1
by: Jason Chan | last post by:
I have a paging datalist which show a list of thumbnail. Above the datalist there is a dropdown to jump to different paging. On Page_load, I bind the datalist according to the current page. On...
3
by: Jon Paal | last post by:
how do I load controls to the templates for the DataList control. <asp:datalist id="dl1" runat="server" > <ItemTemplate> " how to load control(s) here ????" </ItemTemplate>...
0
by: CMELLO | last post by:
I have am dynamically loading a web user control based on the click of a tab strip I load the default control for the first tab in the page load event after checking page is not postback. After...
0
by: =?Utf-8?B?Y2luZHk=?= | last post by:
I have am dynamically loading a web user control based on the click of a tab strip I load the default control for the first tab in the page load event after checking page is not postback. After...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.