views:

158

answers:

1

How can I get asp.net to two-way databind (via Bind("myfieldname")) to a Byte value? I'm storing boolean values in Sql Server to a Byte type and it seems to be looking for boolean. Apparently I need something to convert my datasource's Byte

Looked into creating a method to call like MyConvertMethod(Bind("myfieldname")) but asp.net 4.0 did not allow that with "Bind()" though it allowed it with "Eval()" but Eval only seems to do one way databinding. I looked into the ConvertHandler but seems to be winforms and not webforms.

+2  A: 

I can't answer your question directly, but I can suggest an alternate approach. You can use casting in query or stored procedure to convert the value to a boolean. If the field values can only be 0 or 1, then do this:

cast(field_name as bit) as field_name

If other values (say, 1 and 2) are used, use a case statement to do the casting:

cast(case when field_name = 1 then 0 else 1 end as bit) as field_name
Ray
thanks for the idea - I ended up adding a field to the entityframework partial class that did conversion to bool to and from the byte
DKS