Datalist not repeating...why?`

Discussion in 'ASP .Net' started by Lynn, Aug 16, 2004.

  1. Lynn

    Lynn Guest

    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
     
    Lynn, Aug 16, 2004
    #1
    1. Advertising

  2. Lynn

    Lynn Guest

    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.


    "Lynn" <yeltnab1@_NOSPAM_hotmail.com> wrote in message
    news:...
    > 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
    >
    >
    >
    >
    >
     
    Lynn, Aug 16, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lewis

    datalist repeating first record

    Lewis, Aug 22, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,974
    Ignacio Machin
    Aug 22, 2003
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,964
  3. jobs at webdos
    Replies:
    2
    Views:
    968
    jobs at webdos
    Oct 8, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,228
    Smokey Grindel
    Dec 2, 2006
  5. Lynn

    Datalist not repeating...why?

    Lynn, Aug 16, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    291
Loading...

Share This Page