ternary trouble in datalist/repeater

Discussion in 'ASP .Net' started by Darren, Aug 12, 2004.

  1. Darren

    Darren Guest

    Hi there,

    Recently I have changed languages from VB.NET to C#.

    While in VB.NET, I wrote the below code to determine if a specific
    product in a repeater control had an image. If so, it would display
    the appropriate image; if not, would display a placeholder.gif.

    I now need to convert the below code to C# and am having a brutal time
    at it. I do understand the simple syntax behind using the ternary
    operator
    ie: (bBoolean)?(aImage):(bImage), but for the life of me cannot make
    the below code fly in C#.

    <%# IIf(Container.DataItem("hasimage") = true, "<img
    src='ProductImgSmall/" & Container.DataItem("prodid") ".gif'>",
    "<img 'ProductImgSmall/PlaceHolder.gif' >") %></a>

    Thanks in advance,

    Darren
     
    Darren, Aug 12, 2004
    #1
    1. Advertising

  2. I'm typing this off of the top of my head, so be warned.

    <img src='<%# ((bool)DataBinder.Eval(Container, "DataItem.hasimage")) ?
    string.Format( "ProductImgSmall/{0}.gif", DataBinder.Eval(Container,
    "DataItem.prodid") ) : "ProductImgSmall/PlaceHolder.gif"%>'>

    I'm not familiar with VB.NET, but it seems like it must be doing some
    implicit casting. DataBinder.Eval always returns an object, which sometimes
    needs to be cast (depending on what you're doing). For instance hasimage
    needs to be cast to a bool, but prodid (as an argument to string.Format) does
    not.

    "Darren" wrote:

    > Hi there,
    >
    > Recently I have changed languages from VB.NET to C#.
    >
    > While in VB.NET, I wrote the below code to determine if a specific
    > product in a repeater control had an image. If so, it would display
    > the appropriate image; if not, would display a placeholder.gif.
    >
    > I now need to convert the below code to C# and am having a brutal time
    > at it. I do understand the simple syntax behind using the ternary
    > operator
    > ie: (bBoolean)?(aImage):(bImage), but for the life of me cannot make
    > the below code fly in C#.
    >
    > <%# IIf(Container.DataItem("hasimage") = true, "<img
    > src='ProductImgSmall/" & Container.DataItem("prodid") ".gif'>",
    > "<img 'ProductImgSmall/PlaceHolder.gif' >") %></a>
    >
    > Thanks in advance,
    >
    > Darren
    >
     
    =?Utf-8?B?QnJhZCBRdWlubg==?=, Aug 13, 2004
    #2
    1. Advertising

  3. Darren

    D Smith Guest

    Thanks Brad, you saved my life.

    Cheers,

    Darren


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    D Smith, Aug 13, 2004
    #3
    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. Nevyn Twyll
    Replies:
    8
    Views:
    1,916
  2. Jacob

    ternary operator error

    Jacob, Jun 30, 2003, in forum: Java
    Replies:
    12
    Views:
    4,752
    pete kirkham
    Jul 2, 2003
  3. Ramkumar Menon

    B+ Tree versus Ternary Search Tree

    Ramkumar Menon, Aug 16, 2005, in forum: Java
    Replies:
    2
    Views:
    1,614
    Roedy Green
    Aug 16, 2005
  4. Ramkumar Menon

    B+ Tree versus Ternary Search Tree

    Ramkumar Menon, Aug 16, 2005, in forum: Java
    Replies:
    0
    Views:
    449
    Ramkumar Menon
    Aug 16, 2005
  5. Ramkumar Menon

    B+ Tree versus Ternary Search Tree

    Ramkumar Menon, Aug 16, 2005, in forum: Java
    Replies:
    1
    Views:
    464
    Andrew Thompson
    Aug 16, 2005
Loading...

Share This Page