Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > problem binding visible property to database bit field

Reply
Thread Tools

problem binding visible property to database bit field

 
 
Mark B
Guest
Posts: n/a
 
      03-29-2007
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

 
Reply With Quote
 
 
 
 
Muhammad Naveed Yaseen
Guest
Posts: n/a
 
      03-30-2007
> 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 %>'

 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      03-30-2007
"Muhammad Naveed Yaseen" <> wrote in message
news: ups.com...

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


 
Reply With Quote
 
Muhammad Naveed Yaseen
Guest
Posts: n/a
 
      03-31-2007
> > 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
Hide textbox / Make textbox not visible (NOT USING visible property) Jurjen de Groot ASP .Net Web Controls 0 05-19-2008 09:50 AM
When I change field's visible property to false , error occurs . =?Utf-8?B?bWljaGFlbHM=?= ASP .Net 0 06-01-2006 09:19 AM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57