conditional in GridView Eval binding?

Discussion in 'ASP .Net' started by =?Utf-8?B?RGFiYmxlcg==?=, Jun 27, 2006.

  1. 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.
    =?Utf-8?B?RGFiYmxlcg==?=, Jun 27, 2006
    #1
    1. Advertising

  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" <> wrote in message
    news:...
    > 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.
    Karl Seguin [MVP], Jun 27, 2006
    #2
    1. Advertising

  3. =?Utf-8?B?RGFiYmxlcg==?=

    John Prado Guest

    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.
    John Prado, Jun 27, 2006
    #3
  4. 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" <> wrote in message
    > news:...
    > > 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.

    >
    >
    >
    =?Utf-8?B?RGFiYmxlcg==?=, Jun 27, 2006
    #4
  5. 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.
    >>
    Michael Appelmans, Jun 27, 2006
    #5
  6. =?Utf-8?B?RGFiYmxlcg==?=

    pavansthought

    Joined:
    Dec 2, 2008
    Messages:
    1
    Perfect Solution for this is


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




    It will definitely works :)



    From,
    Pavan kumar.P
    pavansthought, Dec 2, 2008
    #6
  7. =?Utf-8?B?RGFiYmxlcg==?=

    pdx123

    Joined:
    Aug 13, 2009
    Messages:
    1
    I have an issue using if statement in check box gridview

    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...
    pdx123, Aug 13, 2009
    #7
  8. =?Utf-8?B?RGFiYmxlcg==?=

    er_amitthakur

    Joined:
    Jul 29, 2009
    Messages:
    2
    Try this====>

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


    this one is working for me....
    er_amitthakur, Sep 15, 2009
    #8
  9. =?Utf-8?B?RGFiYmxlcg==?=

    april198474

    Joined:
    Sep 17, 2009
    Messages:
    4
    Hey,




    you may try this :

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



    Comm100
    __________________
    Free chat software for you
    Microsoft Certified Partner
    .comm100.com
    april198474, Sep 22, 2009
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Newton
    Replies:
    3
    Views:
    9,378
    Brock Allen
    Apr 4, 2005
  2. Replies:
    3
    Views:
    42,511
  3. Alec S.
    Replies:
    10
    Views:
    10,120
    Alec S.
    Apr 16, 2005
  4. Amit
    Replies:
    6
    Views:
    13,783
    Assimalyst
    Oct 24, 2006
  5. DataBinder.Eval and Eval.

    , Jun 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    540
    Karl Seguin [MVP]
    Jun 16, 2006
Loading...

Share This Page