473,799 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)?(aIm age):(bImage), but for the life of me cannot make
the below code fly in C#.

<%# IIf(Container.D ataItem("hasima ge") = true, "<img
src='ProductImg Small/" & Container.DataI tem("prodid") ".gif'>",
"<img 'ProductImgSmal l/PlaceHolder.gif ' >") %></a>

Thanks in advance,

Darren
Nov 18 '05 #1
2 1457
I'm typing this off of the top of my head, so be warned.

<img src='<%# ((bool)DataBind er.Eval(Contain er, "DataItem.hasim age")) ?
string.Format( "ProductImgSmal l/{0}.gif", DataBinder.Eval (Container,
"DataItem.prodi d") ) : "ProductImgSmal l/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)?(aIm age):(bImage), but for the life of me cannot make
the below code fly in C#.

<%# IIf(Container.D ataItem("hasima ge") = true, "<img
src='ProductImg Small/" & Container.DataI tem("prodid") ".gif'>",
"<img 'ProductImgSmal l/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
7656
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 alright. However with these repeating columns it throws everything out of align because it lets you scroll horizontally but everything else on the page stops where the original right side was. Is there a way it can be set up so that you say repeat...
0
1176
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 tables (approx 5-10 rows by 3-4 columns) of data using repeaters nested in a datalist. Each row in the datalist source will act as a pointer and filter to the child table for the repeater source.
5
3791
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...: <asp:datalist id="DataList1" runat="server"> <HeaderTemplate> <table border="0" cellpadding="0" cellspacing="0" width="400"> <tr> <td width="100">First Name</td>
3
1424
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" RepeatDirection="Vertical" OnItemDataBound="dlChapter_OnItemDataBound"> <ItemTemplate> <table> <tr> <td colspan="2"><%# DataBinder.Eval(Container.DataItem, "ChapterName")%></td>
0
9686
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.