Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > DataBinder.Eval(Container.DataItem ... What is the context of Container?

Reply
Thread Tools

DataBinder.Eval(Container.DataItem ... What is the context of Container?

 
 
Joe Rattz
Guest
Posts: n/a
 
      09-03-2004
I am trying to perform some logic inside a Repeater control's template. I
need that logic dependent on the bound data. If my bound data is < 0, I
want to write one string (a CSS class), otherwise I want to write a
different string (another CSS class). Here is what I am trying to do:

<%
if(Double.Parse(DataBinder.Eval(Container.DataItem , "Amount")) < 0)
{ Response.Write("<span class=\"NewspaperCreditItemAmountN\">"); }
else
{ Response.Write("<span class=\"NewspaperCreditItemAmountP\">"); }
%>

I have formatted the code a little funky so it is easier to read. As you
can see, I want to parse the Amount field into a double and if its < 0, I
want to specify one CSS class, otherwise I want to specify a different
class.

Unfortunately, this code does not work...it doesn't like me accessing
Container this way. I can't seem to find any decent doc on this, but what
is the difference between a <% %> block and a <%# %> block (notice the #)?

I assume the Container object is a member of something. What object can I
get to the Container object from?

Any help would be appreciated. Ultimately, I am trying to change the CSS
style so the dollar amount can be red if negative, otherwise black.

Thanks.


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      09-05-2004
With Repeater Container refers to the current RepeaterItem (basically row)
instance.

You might want to have a look at so called helper function to modularize
what you are trying to do. Here is an article discussing it:
http://aspalliance.com/31

Though the example is with DataGrid, the idea is same for all data-bound
controls like DataGrid, DataList and Repeater.

<% ... %> means just evaluating an expression <%# ... %> means data-binding
expression

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke





"Joe Rattz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am trying to perform some logic inside a Repeater control's template. I
> need that logic dependent on the bound data. If my bound data is < 0, I
> want to write one string (a CSS class), otherwise I want to write a
> different string (another CSS class). Here is what I am trying to do:
>
> <%
> if(Double.Parse(DataBinder.Eval(Container.DataItem , "Amount")) < 0)
> { Response.Write("<span class=\"NewspaperCreditItemAmountN\">"); }
> else
> { Response.Write("<span class=\"NewspaperCreditItemAmountP\">"); }
> %>
>
> I have formatted the code a little funky so it is easier to read. As you
> can see, I want to parse the Amount field into a double and if its < 0, I
> want to specify one CSS class, otherwise I want to specify a different
> class.
>
> Unfortunately, this code does not work...it doesn't like me accessing
> Container this way. I can't seem to find any decent doc on this, but what
> is the difference between a <% %> block and a <%# %> block (notice the #)?
>
> I assume the Container object is a member of something. What object can I
> get to the Container object from?
>
> Any help would be appreciated. Ultimately, I am trying to change the CSS
> style so the dollar amount can be red if negative, otherwise black.
>
> Thanks.
>
>



 
Reply With Quote
 
 
 
 
Robert Koritnik
Guest
Posts: n/a
 
      09-10-2004
<% %> evaluates when the page gets parsed
<%# %> evaluates when the DataBind() method is called

So you should definitely use the # sign. Container gets whatever object that
some collection of them is passed to DataSource. So if you set some
DataTable to DataSource, DataItem is DataRowView...

SOmething else. You could use <%# %> this server side notation regardless of
the databound controls as long as you call the DataBind() method somewhere
in the execution time.

--
RobertK
{ Clever? No just smart. }


"Joe Rattz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am trying to perform some logic inside a Repeater control's template. I
> need that logic dependent on the bound data. If my bound data is < 0, I
> want to write one string (a CSS class), otherwise I want to write a
> different string (another CSS class). Here is what I am trying to do:
>
> <%
> if(Double.Parse(DataBinder.Eval(Container.DataItem , "Amount")) < 0)
> { Response.Write("<span class=\"NewspaperCreditItemAmountN\">"); }
> else
> { Response.Write("<span class=\"NewspaperCreditItemAmountP\">"); }
> %>
>
> I have formatted the code a little funky so it is easier to read. As you
> can see, I want to parse the Amount field into a double and if its < 0, I
> want to specify one CSS class, otherwise I want to specify a different
> class.
>
> Unfortunately, this code does not work...it doesn't like me accessing
> Container this way. I can't seem to find any decent doc on this, but what
> is the difference between a <% %> block and a <%# %> block (notice the #)?
>
> I assume the Container object is a member of something. What object can I
> get to the Container object from?
>
> Any help would be appreciated. Ultimately, I am trying to change the CSS
> style so the dollar amount can be red if negative, otherwise black.
>
> Thanks.
>
>



 
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
Spring context refering to application context Jani Tiainen Java 3 08-27-2007 07:24 AM
return HttpStatusCode.ServiceUnavailable in the context.context.Response.StatusCode (Http response code 503) Flip Rayner ASP .Net 1 01-23-2007 06:35 AM
How to retrieve a session Bean in the Context in a class with the Context reference asd Java 1 11-09-2006 05:00 PM
Strange Context Error: Context 0x197ee0 is disconnected in VS 2005 =?Utf-8?B?U3VuU21pbGU=?= ASP .Net 0 01-10-2006 03:59 PM
Context.Items vs Context.Handler (passing values between pages) VS_NET_DEV ASP .Net 2 05-25-2004 01:16 PM



Advertisments