473,500 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

conditional in GridView Eval binding?

I'm trying to replace a user code in data column with user friendly text for
a GridView ItemTemplate as in:

Text='<%# Eval("LocationType")%> == "P" ? "Pickup" : "DropOff"'

However the value always displays "DropOff" as if the binding doesn't return
any P's but I know there are Ps in the rows I'm testing with.

LocationType is defined as char(1) in the table.

Any suggestion why this isn't working?

Thanks.
Jun 27 '06 #1
4 11094
Your code is wrong. You're mixing server and javascript in the same line.

Try do this in GridView_RowDataBound event

get the data bind for LocationType

do your friendly string

show it in the correspondent cell
Dabbler wrote:
I'm trying to replace a user code in data column with user friendly text for
a GridView ItemTemplate as in:

Text='<%# Eval("LocationType")%> == "P" ? "Pickup" : "DropOff"'

However the value always displays "DropOff" as if the binding doesn't return
any P's but I know there are Ps in the rows I'm testing with.

LocationType is defined as char(1) in the table.

Any suggestion why this isn't working?

Thanks.

Jun 27 '06 #2
Casing? Maybe this will do the trick:

<%# string.Compare(Eval("LocationType"), "P", false) == 0 ? "Pickup" :
"DropOff" %>

you could also try with single quotes in your example...maybe it's a char
<--> string thing, though I doubt it.

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Dabbler" <Da*****@discussions.microsoft.com> wrote in message
news:82**********************************@microsof t.com...
I'm trying to replace a user code in data column with user friendly text
for
a GridView ItemTemplate as in:

Text='<%# Eval("LocationType")%> == "P" ? "Pickup" : "DropOff"'

However the value always displays "DropOff" as if the binding doesn't
return
any P's but I know there are Ps in the rows I'm testing with.

LocationType is defined as char(1) in the table.

Any suggestion why this isn't working?

Thanks.

Jun 27 '06 #3
I it very well may be the char vs string but I can't for the life of me
figure out the single quote setup in this context, as the bind string is
encapsulated with single
quotes ;)

You solution worked when casting the eval to a string as in:

string.Compare((string)Eval("LocationType"), "P",false)==0?"Pickup":"Dropoff"

Thanks much!

"Karl Seguin [MVP]" wrote:
Casing? Maybe this will do the trick:

<%# string.Compare(Eval("LocationType"), "P", false) == 0 ? "Pickup" :
"DropOff" %>

you could also try with single quotes in your example...maybe it's a char
<--> string thing, though I doubt it.

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Dabbler" <Da*****@discussions.microsoft.com> wrote in message
news:82**********************************@microsof t.com...
I'm trying to replace a user code in data column with user friendly text
for
a GridView ItemTemplate as in:

Text='<%# Eval("LocationType")%> == "P" ? "Pickup" : "DropOff"'

However the value always displays "DropOff" as if the binding doesn't
return
any P's but I know there are Ps in the rows I'm testing with.

LocationType is defined as char(1) in the table.

Any suggestion why this isn't working?

Thanks.


Jun 27 '06 #4
Hello John,

Thanks for your suggestion. Managed to keep this all in the Gridview and
avoid code behind solution.

Michael
Your code is wrong. You're mixing server and javascript in the same
line.

Try do this in GridView_RowDataBound event

get the data bind for LocationType

do your friendly string

show it in the correspondent cell

Dabbler wrote:
I'm trying to replace a user code in data column with user friendly
text for a GridView ItemTemplate as in:

Text='<%# Eval("LocationType")%> == "P" ? "Pickup" : "DropOff"'

However the value always displays "DropOff" as if the binding doesn't
return any P's but I know there are Ps in the rows I'm testing with.

LocationType is defined as char(1) in the table.

Any suggestion why this isn't working?

Thanks.

Jun 27 '06 #5

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

Similar topics

2
1244
by: Shafia | last post by:
Hi, My GridView has templated controls in it and I'm binding to an ObjectDataSource. The problem is it refused to bind to my grid column "ColumnName" which is also an UpdateCommand Parameter for...
3
6206
by: washoetech | last post by:
I have a gridview control. In this grid view there is a column for the price of an item. Some of the prices have a dollar sign in front of it and some dont. How do I get rid of the dollar sign...
26
1878
by: onearth | last post by:
Hello I already managed to add a dynamic DetailView under a row of Gridview if a user presses the row with the mouse... Is it possible to add under it a table(or even better load a simple...
1
4559
by: euan | last post by:
HI Guys, I have bee using conditional formatting in the datagrid recently and I am moving over to framework 2.0 and noticed the datagrid has been replaced by the gridview. So, I would like to do...
3
13694
by: idletask | last post by:
I have an SQLDataSource control, which is bound to an ASP.net 2.0 GridView control. It outputs a list of documents that a user can check in or check out of the database. In my gridview, I have...
1
9330
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
0
8547
by: Innova | last post by:
Hi, We are working on a gridview inside the gridview (parent-child) scenario. The data of child grid will depend on the data of parent. Objectives: 1.Add new row in parent grid after each row...
3
7709
by: | last post by:
I'm using the DataList and GridView controls, and I am trying to wrap my head around the problem of conditionally showing or hiding cells/cell content based on the presence or absence of DB data. I...
2
8727
by: Philip | last post by:
I can use a GridView and ObjectDataSource to bind my data using "Eval" expressions ... provided the GridView and related Column TemplateFields are defined as inline HTML. I prefer to...
0
7134
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
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7395
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...
0
5485
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,...
1
4921
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...
0
3108
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...
0
1429
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 ...
0
311
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...

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.