Why is this condition true when it should be false ?

Z

Zenobia

This code, for a page control, is supposed to print a gif (for
each new year, followed by the text of each year). It doesn't do
that. It is just a simplified version of another control used
for demonstration that has the same bug.


1) The <HeaderTemplate> displays the 2004 gif and sets the value
of sPubYY = 2004.

2) When the <ItemTemplate> code executes sPubYY has been set =
2004 (by the <HeaderTemplate> above).

So the initial condition ( Container.DataItem <> sPubYY ) should
be False (because Container.DataItem = 2004 and sPubYY = 2004).
But this condition is True, so the 2004 gif is output again.

I can't understand why this should happen, because sPubYY should
not change value after the <HeaderTemplate> code executes.

How can I display the gif for 2004 (using the <HeaderTemplate>)
but not display it in the <ItemTemplate>?

Please don't suggest the obvious (that I ditch the
<HeaderTemplate>). I need to show the first gif in a slightly
different way to the others.

PS: view state for this control is set to off because the real
control displays a vast amount of data from a dataReader.

+++ +++ +++ +++

<Script Runat="Server">
Public sPubYY As Integer

Sub Page_Load( s As Object, e As EventArgs )
Dim aryDates() As Integer =
{2004,2004,2003,2003,2002,2002,2002,2001,2000,1999}
rptArchive.DataSource = aryDates
rptArchive.DataBind()
End Sub

Function NewYear( yyyy As Integer ) As String
sPubYY = yyyy
Return " <p class='linebelow'><img src= 'images/arc_" &
sPubYY & ".gif' width='120' border='0' alt='" & sPubYY &
"'></p>"
End Function

</Script>

<asp:Repeater
ID="rptArchive"
Runat="Server">
<HeaderTemplate>
<%=NewYear(2004) %>
</HeaderTemplate>

<ItemTemplate>
<%# "Container.DataItem = " & Container.DataItem & "<br>" %>
<%="sPubYY = " & sPubYY & "<br>" %>
<%# "Container.DataItem <> sPubYY = " & (Container.DataItem <>
sPubYY) & "<br>" %>

<%# IIf( Container.DataItem <> sPubYY,
NewYear(Container.DataItem), "") %>
<h4><%# Container.DataItem %></h4>
</ItemTemplate>
</asp:Repeater>

+++ +++ +++ +++
I've included these 3 lines just to illustration variable values

<%# "Container.DataItem = " & Container.DataItem & "<br>" %>
<%="sPubYY = " & sPubYY & "<br>" %>
<%# "Container.DataItem <> sPubYY = " & (Container.DataItem <>
sPubYY) & "<br>" %>

+++ +++ +++ +++
 

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,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top