471,066 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

difference between <%# %> and <$%= %> block

Hi,

i'm using code in my aspx page.

i have data binding where i use <%# Container.DataItem("DateStart") %>
i also use code that makes a loop inside a regular
<%
%>
block
how can i pass data from the databinding to the loop that runs in a regular
block.
if i try to call the Container.DataItem from the regular code block i get
error it is not defined in this stage.
how can i make loop in my data binding stage?
why is this not documented so well?
if there is a link to some good documentation it will be halpfull also.

TIA, z.
Nov 18 '05 #1
3 1606
Jos
"z. f." <zi**@info-scopeREMSPAM.co.il> wrote in message
news:eo**************@TK2MSFTNGP15.phx.gbl...
Hi,

i'm using code in my aspx page.

i have data binding where i use <%# Container.DataItem("DateStart") %>
i also use code that makes a loop inside a regular
<%
%>
block
how can i pass data from the databinding to the loop that runs in a regular block.
if i try to call the Container.DataItem from the regular code block i get
error it is not defined in this stage.
how can i make loop in my data binding stage?
why is this not documented so well?
if there is a link to some good documentation it will be halpfull also.


You need to understand that the <%# %> block is executed
when you call the DataBind() method of the page or control.

The <% %> block is executed during the rendering of the page,
this is after all the events have been handled, all the other code
has been executed, and right before the page is sent to the client.
At that time, the datasource has already been destroyed, which
is why you don't have access to the DataItem.

A good way to solve your problem in ASP.NET would be to
replace the <% %> block by a Literal or Label server control, and
to set the contents of the Literal or Label control right before or
after the DataBind() call.

Jos
Nov 18 '05 #2
i would be glad to accept your suggestion,
the problem is that my code runs in a loop inside a repeater, this why i
had the problem in the first place.

"Jos" <jo***************@fastmail.fm> wrote in message
news:ug**************@TK2MSFTNGP14.phx.gbl...
"z. f." <zi**@info-scopeREMSPAM.co.il> wrote in message
news:eo**************@TK2MSFTNGP15.phx.gbl...
Hi,

i'm using code in my aspx page.

i have data binding where i use <%# Container.DataItem("DateStart") %>
i also use code that makes a loop inside a regular
<%
%>
block
how can i pass data from the databinding to the loop that runs in a

regular
block.
if i try to call the Container.DataItem from the regular code block i get error it is not defined in this stage.
how can i make loop in my data binding stage?
why is this not documented so well?
if there is a link to some good documentation it will be halpfull also.


You need to understand that the <%# %> block is executed
when you call the DataBind() method of the page or control.

The <% %> block is executed during the rendering of the page,
this is after all the events have been handled, all the other code
has been executed, and right before the page is sent to the client.
At that time, the datasource has already been destroyed, which
is why you don't have access to the DataItem.

A good way to solve your problem in ASP.NET would be to
replace the <% %> block by a Literal or Label server control, and
to set the contents of the Literal or Label control right before or
after the DataBind() call.

Jos

Nov 18 '05 #3
Move all the code into the OnItemDataBound event handler something like this

private void dlMailing_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
DbDataRecord dbr = (DbDataRecord)e.Item.DataItem;
CheckBox cb = (CheckBox )e.Item.FindControl ("cbSubscribe") ;
Label lb = (Label )e.Item.FindControl ("lblMailingList") ;
cb.Text = dbr["Name"].ToString () ;
lb.Text = dbr["Description"].ToString () ;

// Some loop here....

}
}
Stephen
"z. f." <zi**@info-scopeREMSPAM.co.il> wrote in message
news:uj**************@TK2MSFTNGP14.phx.gbl...
i would be glad to accept your suggestion,
the problem is that my code runs in a loop inside a repeater, this why i
had the problem in the first place.

"Jos" <jo***************@fastmail.fm> wrote in message
news:ug**************@TK2MSFTNGP14.phx.gbl...
"z. f." <zi**@info-scopeREMSPAM.co.il> wrote in message
news:eo**************@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> i'm using code in my aspx page.
>
> i have data binding where i use <%# Container.DataItem("DateStart") %>
> i also use code that makes a loop inside a regular
> <%
> %>
> block
> how can i pass data from the databinding to the loop that runs in a

regular
> block.
> if i try to call the Container.DataItem from the regular code block i get > error it is not defined in this stage.
> how can i make loop in my data binding stage?
> why is this not documented so well?
> if there is a link to some good documentation it will be halpfull also.


You need to understand that the <%# %> block is executed
when you call the DataBind() method of the page or control.

The <% %> block is executed during the rendering of the page,
this is after all the events have been handled, all the other code
has been executed, and right before the page is sent to the client.
At that time, the datasource has already been destroyed, which
is why you don't have access to the DataItem.

A good way to solve your problem in ASP.NET would be to
replace the <% %> block by a Literal or Label server control, and
to set the contents of the Literal or Label control right before or
after the DataBind() call.

Jos


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

34 posts views Thread by Mark Moore | last post: by
3 posts views Thread by Josef K. | last post: by
36 posts views Thread by Roedy Green | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.