Changing Repeater ItemTemplate

M

mj.redfox.mj

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!
 
E

Eliyahu Goldin

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
 
M

mj.redfox.mj

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!
 

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,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top