spageti code in asp.net

T

TomislaW

why this is not possible in asp.net?
error:
CS0103: The name 'i' does not exist in the class or namespace...

<%
int i = 0;
%>

<asp:Repeater ID="RepeaterSoba" Runat="server" EnableViewState="False"
DataSource='<%# (DataBinder.Eval(Container.DataItem, "EtazaId"))%>'>
<HeaderTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="0" ID="Table2">
</HeaderTemplate>
<ItemTemplate>

<%
i = i + 1;
%>
 
J

John Saunders

TomislaW said:
why this is not possible in asp.net?
error:
CS0103: The name 'i' does not exist in the class or namespace...

<%
int i = 0;
%>

<asp:Repeater ID="RepeaterSoba" Runat="server" EnableViewState="False"
DataSource='<%# (DataBinder.Eval(Container.DataItem, "EtazaId"))%>'>
<HeaderTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="0"
ID="Table2">
</HeaderTemplate>
<ItemTemplate>

<%
i = i + 1;
%>

What it said.

Which class is "i" declared in? Which class is it being referenced in?

John Saunders
 
P

Patrice

IMO have a look at the source code created for this construction. It's
likely created as distinct pieces of code or something preventing the "i"
variable to be know accross distinct pieces of code.

Note also that this is probably because ASP.NET doesn't just copy any more
the "HTML" fragments to the output stream. Server side tags needs to be
processed server side in a more complex manner and the code fragments have
to fit in this scheme.

Patrice
 
J

John Timney \(ASP.NET MVP\)

you can code like this

<%
int i = 0;
%>

or you can code like this

<asp:Repeater ID="RepeaterSoba" Runat="server" EnableViewState="False" >

The page is composed of component parts, when you tell it to use a server
side component it expects to see a particular type of coding convention in
the page - whinc does not include random code.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
P

Patrice

I gave this a look. The two code fragments are in distinct rendering
routines (as they are not at the same level in the controls tree).

Patrice
--
 
T

TomislaW

it is not always everything so simple as microsoft says
i have repeater inside other repeater
i need number of rows for second repeater
 
P

Patrice

Try to use the "script" tag instead of <%. With the script tag, ASP.NET
consider this as a "stand alone" piece of code and it is included outside of
any rendering procedure. This way you'll have a variable that is global to
your page alloiwng to access it from other location.

Patrice
--
 
K

Kevin Spencer

Try being object-oriented. ASP.Net is.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
G

Guest

try using
Level2RepeaterName.Items.Count

TomislaW said:
it is not always everything so simple as microsoft says
i have repeater inside other repeater
i need number of rows for second repeater
 

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

Top