problem binding visible property to database bit field

  • Thread starter Thread starter Mark B
  • Start date Start date
M

Mark B

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
 
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 %>'
 
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...
 
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.
 
Back
Top