0

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.

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.