Changing Repeater ItemTemplate

Discussion in 'ASP .Net' started by mj.redfox.mj@gmail.com, Feb 20, 2007.

  1. Guest

    Hi,

    I wonder if someone could possibly help with this? I have the
    following code, which is a nested repeater in turn nesting a datalist.
    This all works fine, together with my page-behind vb code controlling
    the relations etc.

    Now, what I'm wanting to do is to call a subroutine 'subroutine1' when
    the repeater is data bound, which I'm wanting to use to change the
    background colour of table cell tdCell1 depending on the value of
    intValue1 in the repeater's data collection...



    <asp:Repeater ID="repeater1" runat="server" DataSource='<
    %#Container.DataItem.Row.GetChildRows("intValue1")%>'
    OnItemDataBound="subroutine1">
    <ItemTemplate>
    <asp:Table ID="table1" runat="server">
    <asp:TableRow>
    <asp:TableCell ID="tdCell1">
    <asp:DataList ID="datalist1" runat="server" DataSource='<
    %#Container.DataItem.GetChildRows("relation2")%>'>
    <ItemTemplate><%#Container.DataItem("intValue2")%></
    ItemTemplate>
    </asp:DataList>
    </asp:TableCell>
    </asp:TableRow>
    </asp:Table>
    </ItemTemplate>
    </asp:Repeater>



    I'm struggling with the syntax of how I'd do this. I think I may be
    nearly there with the code below, although not quite (this particular
    attempt brings back a "Public member 'Row' on type 'DataRow' not
    found" error). I'd be grateful if anyone could help as I can't seem to
    find any real examples on the net of what I'm trying to do.



    Public Sub subroutine1(ByVal Sender As Object, ByVal e As
    RepeaterItemEventArgs)

    Dim tdCell1 As TableCell = e.Item.FindControl("tdCell1")
    Dim intTest As Integer =
    e.Item.DataItem.Row.GetChildRows("intValue1")

    If intTest > 5 Then
    tdCell1.BackColor = Drawing.Color.GreenYellow
    End If

    End Sub



    The frustrating thing is that I could do this in five minutes flat in
    normal ASP with a nested recordset, but it seems so much more
    difficult to do it in .NET. Thanks so much in advance for any
    suggestions!
    , Feb 20, 2007
    #1
    1. Advertising

  2. First, you probably want to take the <asp:Table ID="table1" runat="server">
    and </asp:Table> lines outside the repeater. Then the repeater will produce
    just one table with items instead of each item being in a separate table.

    Second, e.Item.DataItem is a DataRow itself, it neither has no needs any Row
    member.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    <> wrote in message
    news:...
    > Hi,
    >
    > I wonder if someone could possibly help with this? I have the
    > following code, which is a nested repeater in turn nesting a datalist.
    > This all works fine, together with my page-behind vb code controlling
    > the relations etc.
    >
    > Now, what I'm wanting to do is to call a subroutine 'subroutine1' when
    > the repeater is data bound, which I'm wanting to use to change the
    > background colour of table cell tdCell1 depending on the value of
    > intValue1 in the repeater's data collection...
    >
    >
    >
    > <asp:Repeater ID="repeater1" runat="server" DataSource='<
    > %#Container.DataItem.Row.GetChildRows("intValue1")%>'
    > OnItemDataBound="subroutine1">
    > <ItemTemplate>
    > <asp:Table ID="table1" runat="server">
    > <asp:TableRow>
    > <asp:TableCell ID="tdCell1">
    > <asp:DataList ID="datalist1" runat="server" DataSource='<
    > %#Container.DataItem.GetChildRows("relation2")%>'>
    > <ItemTemplate><%#Container.DataItem("intValue2")%></
    > ItemTemplate>
    > </asp:DataList>
    > </asp:TableCell>
    > </asp:TableRow>
    > </asp:Table>
    > </ItemTemplate>
    > </asp:Repeater>
    >
    >
    >
    > I'm struggling with the syntax of how I'd do this. I think I may be
    > nearly there with the code below, although not quite (this particular
    > attempt brings back a "Public member 'Row' on type 'DataRow' not
    > found" error). I'd be grateful if anyone could help as I can't seem to
    > find any real examples on the net of what I'm trying to do.
    >
    >
    >
    > Public Sub subroutine1(ByVal Sender As Object, ByVal e As
    > RepeaterItemEventArgs)
    >
    > Dim tdCell1 As TableCell = e.Item.FindControl("tdCell1")
    > Dim intTest As Integer =
    > e.Item.DataItem.Row.GetChildRows("intValue1")
    >
    > If intTest > 5 Then
    > tdCell1.BackColor = Drawing.Color.GreenYellow
    > End If
    >
    > End Sub
    >
    >
    >
    > The frustrating thing is that I could do this in five minutes flat in
    > normal ASP with a nested recordset, but it seems so much more
    > difficult to do it in .NET. Thanks so much in advance for any
    > suggestions!
    >
    Eliyahu Goldin, Feb 20, 2007
    #2
    1. Advertising

  3. Guest

    Hello Eliyahu,

    Sorry, forgot to explain, this is really a trimmed-down version of my
    code with just the relevant parts retained, I actually need the
    repeater to generate a new self-contained table each time, that part's
    by design.

    You've pointed out my mistake perfectly, can't believe what I was
    doing now I look at it again! By changing the following...

    e.Item.DataItem.Row.GetChildRows("intValue1")

    ....to this...

    e.Item.DataItem("intValue1").ToString

    ....I get the results I wanted. Sorry, I don't know what I was doing
    using the syntax for referencing a relationship in the first place.

    Thanks for your help and time, it's very much appreciated!
    , Feb 20, 2007
    #3
    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. Bennett Haselton
    Replies:
    1
    Views:
    5,312
    Joe Fallon
    Sep 24, 2004
  2. Shimon Sim

    Repeater.ItemTemplate =?

    Shimon Sim, Jan 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    939
    Karl Seguin
    Jan 27, 2005
  3. Replies:
    3
    Views:
    1,564
    Eliyahu Goldin
    Aug 16, 2005
  4. Mike
    Replies:
    1
    Views:
    599
    Alec MacLean
    Feb 4, 2006
  5. Sachin
    Replies:
    1
    Views:
    1,175
    sloan
    Feb 21, 2006
Loading...

Share This Page