problem binding visible property to database bit field

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
 
M

Muhammad Naveed Yaseen

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 %>'
 
M

Mark Rae

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...
 
M

Muhammad Naveed Yaseen

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top