473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ternary trouble in datalist/repeater

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
Nov 18 '05 #1
2 1444
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

Nov 18 '05 #2

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!
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Gav | last post by:
Hi All, I have created a datalist using the repeatcolumns property to create multiple columns. I have tried to keep everythings width to 100% so that if the window is resized it still looks...
0
by: Shun Duke | last post by:
I have working code allowing me to nest repeaters inside datalists using relations and child rows but this does not allow me to acheive my goal. What I want to be able to do is display small...
5
by: Ben Fidge | last post by:
I'm using DataList to present tabular data but am often having problems with some rows column alignment being out of synch with the rest of the rows. My DataList looks similar to this...: ...
3
by: GD | last post by:
I'm using a DataList and a Repeater (nested in the DataList) to display a list of "Chapters" and "Documents" within the Chapters. <asp:DataList ID="dlChapter" Runat="server" RepeatColumns="2"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.