Conditional use of Eval in asp.net 2.0 with Gridview

Discussion in 'ASP .Net' started by idletask@msn.com, Jan 30, 2006.

  1. Guest

    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 a column called "checked out" which is bound to
    a column in my database, called "checkedout". A zero means no, and a
    one means yes (that the document is checked out).

    Showing a 0 or 1 is ugly and I want to use No or Yes. I can't figure
    out how to get at my SQLDataSource control's rows so that I can look at
    them and write text out, rather than what's in the database (a 0 or 1).

    My code is like this:

    <asp:Label ID="CheckedOut" runat="server" text='<%# Eval("CheckedOut")
    %>' />

    I've tried assiging the return value of Eval("CheckedOut") to a local
    variable, but I get asp errors telling me that Eval must be used in a
    databound control.

    I want to do something like this:

    If Eval("CheckedOut") = "0" Then
    ...
    Else
    ...
    End Of

    I can post real code if that helps- but it's more the approach I am
    looking for...

    Thanks for any help

    idletask.
     
    , Jan 30, 2006
    #1
    1. Advertising

  2. You could write a custom function and bind to that instead.

    <asp:Label ID="CheckedOut" runat="server"
    text='<%# GetCheckedOutValue((int)DataBinder.Eval(Container.DataItem,
    "CheckedOut")) %> />

    Then in code behind or inline:
    protected string GetCheckedOutValue(int checkedOut)
    {
    if(checkedOut == 0)
    return "True";
    else
    return "False";
    }

    "" wrote:

    > 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 a column called "checked out" which is bound to
    > a column in my database, called "checkedout". A zero means no, and a
    > one means yes (that the document is checked out).
    >
    > Showing a 0 or 1 is ugly and I want to use No or Yes. I can't figure
    > out how to get at my SQLDataSource control's rows so that I can look at
    > them and write text out, rather than what's in the database (a 0 or 1).
    >
    > My code is like this:
    >
    > <asp:Label ID="CheckedOut" runat="server" text='<%# Eval("CheckedOut")
    > %>' />
    >
    > I've tried assiging the return value of Eval("CheckedOut") to a local
    > variable, but I get asp errors telling me that Eval must be used in a
    > databound control.
    >
    > I want to do something like this:
    >
    > If Eval("CheckedOut") = "0" Then
    > ...
    > Else
    > ...
    > End Of
    >
    > I can post real code if that helps- but it's more the approach I am
    > looking for...
    >
    > Thanks for any help
    >
    > idletask.
    >
    >
     
    =?Utf-8?B?Q2hhc2U=?=, Jan 30, 2006
    #2
    1. Advertising

  3. sloan Guest

    The wrapper function is my suggestion also.


    That's kinda what "presentation" layer means.

    You "present" the data the way you want to.

    Keep in mind, that if you want to edit, you need to use a checkbox.
    Or write a custom user control...which maybe has a drop down list of
    --Select--
    True
    False

    .....



    <> wrote in message
    news:...
    >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 a column called "checked out" which is bound to
    > a column in my database, called "checkedout". A zero means no, and a
    > one means yes (that the document is checked out).
    >
    > Showing a 0 or 1 is ugly and I want to use No or Yes. I can't figure
    > out how to get at my SQLDataSource control's rows so that I can look at
    > them and write text out, rather than what's in the database (a 0 or 1).
    >
    > My code is like this:
    >
    > <asp:Label ID="CheckedOut" runat="server" text='<%# Eval("CheckedOut")
    > %>' />
    >
    > I've tried assiging the return value of Eval("CheckedOut") to a local
    > variable, but I get asp errors telling me that Eval must be used in a
    > databound control.
    >
    > I want to do something like this:
    >
    > If Eval("CheckedOut") = "0" Then
    > ...
    > Else
    > ...
    > End Of
    >
    > I can post real code if that helps- but it's more the approach I am
    > looking for...
    >
    > Thanks for any help
    >
    > idletask.
    >
     
    sloan, Jan 31, 2006
    #3
  4. Guest

    Another option would be in the DB itself, send another column which has
    the value of true/false, based on the value of this column which is 0/1

    sloan wrote:
    > The wrapper function is my suggestion also.
    >
    >
    > That's kinda what "presentation" layer means.
    >
    > You "present" the data the way you want to.
    >
    > Keep in mind, that if you want to edit, you need to use a checkbox.
    > Or write a custom user control...which maybe has a drop down list of
    > --Select--
    > True
    > False
    >
    > ....
    >
    >
    >
    > <> wrote in message
    > news:...
    > >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 a column called "checked out" which is bound to
    > > a column in my database, called "checkedout". A zero means no, and a
    > > one means yes (that the document is checked out).
    > >
    > > Showing a 0 or 1 is ugly and I want to use No or Yes. I can't figure
    > > out how to get at my SQLDataSource control's rows so that I can look at
    > > them and write text out, rather than what's in the database (a 0 or 1).
    > >
    > > My code is like this:
    > >
    > > <asp:Label ID="CheckedOut" runat="server" text='<%# Eval("CheckedOut")
    > > %>' />
    > >
    > > I've tried assiging the return value of Eval("CheckedOut") to a local
    > > variable, but I get asp errors telling me that Eval must be used in a
    > > databound control.
    > >
    > > I want to do something like this:
    > >
    > > If Eval("CheckedOut") = "0" Then
    > > ...
    > > Else
    > > ...
    > > End Of
    > >
    > > I can post real code if that helps- but it's more the approach I am
    > > looking for...
    > >
    > > Thanks for any help
    > >
    > > idletask.
    > >
     
    , Feb 27, 2006
    #4
    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,409
    Brock Allen
    Apr 4, 2005
  2. Alec S.
    Replies:
    10
    Views:
    10,155
    Alec S.
    Apr 16, 2005
  3. DataBinder.Eval and Eval.

    , Jun 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    546
    Karl Seguin [MVP]
    Jun 16, 2006
  4. =?Utf-8?B?RGFiYmxlcg==?=

    conditional in GridView Eval binding?

    =?Utf-8?B?RGFiYmxlcg==?=, Jun 27, 2006, in forum: ASP .Net
    Replies:
    8
    Views:
    46,786
    april198474
    Sep 22, 2009
  5. Alex van der Spek

    eval('07') works, eval('08') fails, why?

    Alex van der Spek, Jan 8, 2009, in forum: Python
    Replies:
    6
    Views:
    1,450
    Bruno Desthuilliers
    Jan 8, 2009
Loading...

Share This Page