Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > using Eval ("ZZZ")

Reply
Thread Tools

using Eval ("ZZZ")

 
 
Rick Mavrovik
Guest
Posts: n/a
 
      07-03-2007
Hi,
I am using repeater bound to a dataset.
Within the repeater I have got ItemTemplate in which I am displaying data by
using
Eval("DataFieldName").

Does anyone know how can I perform any calculation in ItemTemplate on the
bound data..For instance. I need to display an image based on some rule like
if Eval("ThisField") is greater than Eval("ThatField").

Any clue?

-Rick


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      07-03-2007
Howdy,

Two ways:
1. Bound expressions

usually this gets messy for complex expressions

<ItemTemplate>
<asp:Label runat="server" ID="lab"
Text='<%# (int) Eval("DataField") > 0 ? "Greater" : "Less or Equal" %>'/>
</ItemTemplate>

2. Handling ItemDataBound event
protected void repeater_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;

if (item.ItemType == ListItemType.Item ||
item.ItemType == ListItemType.AlternatingItem)
{
Label label = (Label)item.FindControl("lab");

DataRow row = ((DataRowView) item.DataItem).Row;

int value = (int) row["DataField"];

label.Text = value > 0 ? "Greater" : "Less or Equal";
}
}

hope this helps
--
Milosz


"Rick Mavrovik" wrote:

> Hi,
> I am using repeater bound to a dataset.
> Within the repeater I have got ItemTemplate in which I am displaying data by
> using
> Eval("DataFieldName").
>
> Does anyone know how can I perform any calculation in ItemTemplate on the
> bound data..For instance. I need to display an image based on some rule like
> if Eval("ThisField") is greater than Eval("ThatField").
>
> Any clue?
>
> -Rick
>
>
>

 
Reply With Quote
 
 
 
 
Roland Dick
Guest
Posts: n/a
 
      07-03-2007
Hi,

in addition to the solutions Milosz gave you, here's a third way: call a
code-behind method on the bound data.

<ItemTemplate>
<asp:Label runat="server" ID="lab"
Text='<%# MyMethod(Container.DataItem) %>'/>
</ItemTemplate>

and in the code behind:

protected string MyMethod (object DataItem)
{
DataRowView dr = DataItem as DataRowView;
if (dr == null)
return "";
return dr["Column1"].ToString() + dr["Column2"].ToString();
}

....or whatever you need to do there. You can also pass additional
parameters.

Roland
 
Reply With Quote
 
vMike
Guest
Posts: n/a
 
      07-03-2007

"Rick Mavrovik" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
> I am using repeater bound to a dataset.
> Within the repeater I have got ItemTemplate in which I am displaying data
> by using
> Eval("DataFieldName").
>
> Does anyone know how can I perform any calculation in ItemTemplate on the
> bound data..For instance. I need to display an image based on some rule
> like if Eval("ThisField") is greater than Eval("ThatField").
>
> Any clue?
>
> -Rick
>

One additional solution -- add a column to your data which does the
calculation and then use that field name.

mike


 
Reply With Quote
 
Rick Mavrovik
Guest
Posts: n/a
 
      07-04-2007
Thanks everyone!

"vMike" <(E-Mail Removed)> wrote in message
news:cBwii.17$(E-Mail Removed)...
>
> "Rick Mavrovik" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Hi,
>> I am using repeater bound to a dataset.
>> Within the repeater I have got ItemTemplate in which I am displaying data
>> by using
>> Eval("DataFieldName").
>>
>> Does anyone know how can I perform any calculation in ItemTemplate on the
>> bound data..For instance. I need to display an image based on some rule
>> like if Eval("ThisField") is greater than Eval("ThatField").
>>
>> Any clue?
>>
>> -Rick
>>

> One additional solution -- add a column to your data which does the
> calculation and then use that field name.
>
> mike
>
>



 
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
to eval or not to eval? Marc Girod Perl Misc 2 04-19-2011 01:13 PM
eval('07') works, eval('08') fails, why? Alex van der Spek Python 6 01-08-2009 08:24 PM
Different behavior between eval "07" and eval "08" Liang Wang Perl Misc 8 02-02-2008 08:31 PM
DataBinder.Eval and Eval. craigkenisston@hotmail.com ASP .Net 1 06-16-2006 05:33 PM
DataBinder.Eval for an object's property property... like Eval(Container.DataItem,"Version.Major") Eric Newton ASP .Net 3 04-04-2005 10:11 PM



Advertisments