conditional in GridView Eval binding?

G

Guest

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.
 
K

Karl Seguin [MVP]

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
 
J

John Prado

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
 
G

Guest

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!
 
M

Michael Appelmans

Hello John,

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

Michael
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top