Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > conditional in GridView Eval binding?

Reply
Thread Tools

conditional in GridView Eval binding?

 
 
=?Utf-8?B?RGFiYmxlcg==?=
Guest
Posts: n/a
 
      06-27-2006
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.
 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      06-27-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
 
John Prado
Guest
Posts: n/a
 
      06-27-2006
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.

 
Reply With Quote
 
=?Utf-8?B?RGFiYmxlcg==?=
Guest
Posts: n/a
 
      06-27-2006
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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.

>
>
>

 
Reply With Quote
 
Michael Appelmans
Guest
Posts: n/a
 
      06-27-2006
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.
>>



 
Reply With Quote
 
pavansthought pavansthought is offline
Junior Member
Join Date: Dec 2008
Posts: 1
 
      12-02-2008
Perfect Solution for this is


<asp:TemplateField HeaderText="User Name">
<ItemTemplate>
<asp:Label ID="lblUName" runat="server" Text='<%# String.Compare((string)Eval("LocationType"),"P",fa lse)==0?"Pickup":"Dropoff" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>




It will definitely works



From,
Pavan kumar.P
 
Reply With Quote
 
pdx123 pdx123 is offline
Junior Member
Join Date: Aug 2009
Posts: 1
 
      08-13-2009
Here is my code:

<%# String.Compare((string)Eval("request"),"1",fa lse)==0?"<img src='imges001.png'>":"<asp:checkbox ID='s1' Runat='server' " %>


It doesn't show the checkbox, display nothing.... any suggestion. Thanks...
 
Reply With Quote
 
er_amitthakur er_amitthakur is offline
Junior Member
Join Date: Jul 2009
Posts: 2
 
      09-15-2009
Try this====>

<input type="checkbox" <%# String.Compare((string)Eval("select_priv"),"t",fal se)==0?"checked=\"true\"":"" %> />


this one is working for me....
 
Reply With Quote
 
april198474 april198474 is offline
Junior Member
Join Date: Sep 2009
Posts: 6
 
      09-22-2009
Hey,




you may try this :

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



Comm100
__________________
Free chat software for you
Microsoft Certified Partner
.comm100.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
eval('07') works, eval('08') fails, why? Alex van der Spek Python 6 01-08-2009 08:24 PM
DataBinder.Eval and Eval. craigkenisston@hotmail.com ASP .Net 1 06-16-2006 05:33 PM
Conditional use of Eval in asp.net 2.0 with Gridview idletask@msn.com ASP .Net 3 02-27-2006 05:45 AM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM
DataBinder.Eval for an object's property property... like Eval(Container.DataItem,"Version.Major") Eric Newton ASP .Net 3 04-04-2005 10:11 PM



Advertisments