using Eval ("ZZZ")

Discussion in 'ASP .Net' started by Rick Mavrovik, Jul 3, 2007.

  1. 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
    Rick Mavrovik, Jul 3, 2007
    #1
    1. Advertising

  2. 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
    >
    >
    >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Jul 3, 2007
    #2
    1. Advertising

  3. Rick Mavrovik

    Roland Dick Guest

    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
    Roland Dick, Jul 3, 2007
    #3
  4. Rick Mavrovik

    vMike Guest

    "Rick Mavrovik" <> wrote in message
    news:%...
    > 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
    vMike, Jul 3, 2007
    #4
  5. Thanks everyone!

    "vMike" <> wrote in message
    news:cBwii.17$...
    >
    > "Rick Mavrovik" <> wrote in message
    > news:%...
    >> 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
    >
    >
    Rick Mavrovik, Jul 4, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Newton
    Replies:
    3
    Views:
    9,355
    Brock Allen
    Apr 4, 2005
  2. DataBinder.Eval and Eval.

    , Jun 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    523
    Karl Seguin [MVP]
    Jun 16, 2006
  3. abdulet
    Replies:
    2
    Views:
    531
    abdulet
    Oct 23, 2009
  4. Jake
    Replies:
    5
    Views:
    126
  5. Mel
    Replies:
    1
    Views:
    114
    scripts.contact
    Apr 3, 2007
Loading...

Share This Page