problem binding visible property to database bit field

Discussion in 'ASP .Net' started by Mark B, Mar 29, 2007.

  1. Mark B

    Mark B Guest

    I have a gridview that contains a linkButton in a template field. I
    want to set the visibility of the linkbutton based on a bit field in a
    database.

    Selecting the proper field in editbindings gives this in the code
    Visible='<%# Eval("completed") %>'. (where "completed" is a bit field
    in a sql server database)

    This generates the following error.

    Exception Details: System.InvalidCastException: Specified cast is not
    valid.

    Line 120: <asp:LinkButton ID="lbWorkFlow" runat="server"
    CommandName="Select" text="Mark Completed"
    Line 121: CommandArgument='<%# Eval("stepIdNo", "{0}") %>' Visible='<
    %# Eval("completed") %>' ></asp:LinkButton>

    I know it's reading the database because if I bind the same field to
    the text property, it changes the text to "True" or "False".


    Thanks in advance,


    Mark B
     
    Mark B, Mar 29, 2007
    #1
    1. Advertising

  2. > I know it's reading the database because if I bind the same field to
    > the text property, it changes the text to "True" or "False".


    That don't sound right. In SQL server Bit field has two states, 1 or
    0. Deciding which one of these is true/false, yes/no or male/female
    etc is upon user's discretion.
    Try following instead

    Visible='< %# (1 == (int) Eval("completed"))? true : false %>'
     
    Muhammad Naveed Yaseen, Mar 30, 2007
    #2
    1. Advertising

  3. Mark B

    Mark Rae Guest

    "Muhammad Naveed Yaseen" <> wrote in message
    news:...

    >> I know it's reading the database because if I bind the same field to
    >> the text property, it changes the text to "True" or "False".

    >
    > That don't sound right.


    Yes it does.

    > In SQL server Bit field has two states, 1 or 0.


    Yes, but these are rendered as "True" or "False" by the time the data has
    been bound... Incidentally, if you open a SQL Server table directly in
    Enterprise Manager, bit values are displayed as True or False, not 1 or 0...
     
    Mark Rae, Mar 30, 2007
    #3
  4. > > InSQLserverBitfield has two states, 1 or 0.
    >
    > Yes, but these are rendered as "True" or "False" by the time the data has
    > been bound... Incidentally, if you open aSQLServertable directly in
    > Enterprise Manager,bitvalues are displayed as True or False, not 1 or 0...


    On mine it is showing 1 and 0. And binding to TextBox is also showing
    1 and 0.
    May be your server's version or configuration is different than mine.

    Oh well. In any case then '<%# bool.Parse(Eval("completed") as string)
    %>' should do it.
     
    Muhammad Naveed Yaseen, Mar 31, 2007
    #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. =?Utf-8?B?bWljaGFlbHM=?=
    Replies:
    0
    Views:
    351
    =?Utf-8?B?bWljaGFlbHM=?=
    Jun 1, 2006
  2. Replies:
    2
    Views:
    458
  3. Replies:
    3
    Views:
    1,847
    Timothy Bendfelt
    Jan 19, 2007
  4. Replies:
    9
    Views:
    1,046
    Juha Nieminen
    Aug 22, 2007
  5. Jurjen de Groot
    Replies:
    0
    Views:
    330
    Jurjen de Groot
    May 19, 2008
Loading...

Share This Page