Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Changing Repeater ItemTemplate

Reply
Thread Tools

Changing Repeater ItemTemplate

 
 
mj.redfox.mj@gmail.com
Guest
Posts: n/a
 
      02-20-2007
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">
<aspataList ID="datalist1" runat="server" DataSource='<
%#Container.DataItem.GetChildRows("relation2")%>'>
<ItemTemplate><%#Container.DataItem("intValue2")%> </
ItemTemplate>
</aspataList>
</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!

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-20-2007
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


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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">
> <aspataList ID="datalist1" runat="server" DataSource='<
> %#Container.DataItem.GetChildRows("relation2")%>'>
> <ItemTemplate><%#Container.DataItem("intValue2")%> </
> ItemTemplate>
> </aspataList>
> </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!
>



 
Reply With Quote
 
 
 
 
mj.redfox.mj@gmail.com
Guest
Posts: n/a
 
      02-20-2007
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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET: Repeater: RadioButtons in ItemTemplate Sachin ASP .Net 1 02-21-2006 08:47 PM
Changing Repeater ItemTemplate details based on data from dataset Mike ASP .Net 1 02-04-2006 08:32 AM
multiple <td> in a repeater control <ItemTemplate> (asp.net 2) webserverpete@ebtech.net ASP .Net 3 08-16-2005 01:43 PM
Repeater.ItemTemplate =? Shimon Sim ASP .Net 1 01-27-2005 11:34 PM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM



Advertisments