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:
<aspataList id="Datalist2" runat="server" ShowHeader="true"
ShowFooter="true" Width="100%" HorizontalAlign="Center"
RepeatDirection="Horizontal" RepeatColumns="2" DataSource="<%# DsHomeFronts1
%>"></aspataList>
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
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:
<aspataList id="Datalist2" runat="server" ShowHeader="true"
ShowFooter="true" Width="100%" HorizontalAlign="Center"
RepeatDirection="Horizontal" RepeatColumns="2" DataSource="<%# DsHomeFronts1
%>"></aspataList>
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