Datalist not repeating...why?`

L

Lynn

Hello,

Sorry for the double post...I meant for this to go into this forum.

I have built a datalist programatically using an article from MSDN...the
article was written specifically for the Repeater control, but says it can
be used with a datalist.
(MSDN article here
http://msdn.microsoft.com/library/d...atingwebservercontroltemplatesdynamically.asp)

Well, for some reason, I can't get my datalist to repeat mutliple columns,
event though I have this set in my Datalist control: RepeatColumns="2". I am
only getting one column.

I assume I am missing something in my code...could somebody take a look? I
am new to .net and not sure what is causing this. I have included the code
frome my code behind page as well as my datalist control from the aspx
page...see below.

Thank you for the help!

Lynn

This is what is in my aspx page:
<asp:DataList id="Datalist2" runat="server" ShowHeader="true"
ShowFooter="true" Width="100%" HorizontalAlign="Center"
RepeatDirection="Horizontal" RepeatColumns="2" DataSource="<%# DsHomeFronts1
%>"></asp:DataList>

And here is my code behind stuff...this is modified from the MSDN article...

Private Class MyTemplate

Implements ITemplate

Shared itemcount As Integer = 0

Dim TemplateType As ListItemType

Sub New(ByVal type As ListItemType)

TemplateType = type

End Sub

Sub InstantiateIn(ByVal container As Control) _

Implements ITemplate.InstantiateIn

Dim lc As New Literal

'lc.Text &= "RepeatColumns='2'"

Select Case TemplateType

Case ListItemType.Header

lc.Text = "<HeaderTemplate>My Header<br /><br /></HeaderTemplate>"

Case ListItemType.Item

AddHandler lc.DataBinding, AddressOf TemplateControl_DataBinding

Case ListItemType.AlternatingItem

'lc.Text = "<AlternatingItemTemplate>Alt Item</AlternatingItemTemplate>"

Case ListItemType.Footer

lc.Text = "<FooterTemplate><br /><br />My Footer</FooterTemplate>"

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.NamingContainer, DataListItem)

lc.Text &= "<ItemTemplate>"

lc.Text &= DataBinder.Eval(container.DataItem, "strImagePath") & "<br />"

lc.Text &= DataBinder.Eval(container.DataItem, "strAddress") & "<br />"

lc.Text &= DataBinder.Eval(container.DataItem, "intPrice") & "<br />"

Dim MyTemp1 As String

Select Case DataBinder.Eval(container.DataItem, "intStatus")

Case 1

MyTemp1 = "Active"

Case 2

MyTemp1 = "Pending"

Case 3

MyTemp1 = "Sold"

End Select

lc.Text &= MyTemp1 & "<hr />"

lc.Text &= "</ItemTemplate>"

End Sub

End Class
 
L

Lynn

I found the problem...

for some reason (unknown to me) have the alternatingitem lines in my code
was messing up the repeat...removed reference to that and it worked fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top