简体   繁体   中英

How to convert binding value type into another in aspx?

I have this code:

<asp:CheckBox ID="CheckBoxAppStatus" runat="server" Text="Done" Checked='<%# Bind("Status") %>'/>  

The problem is that Bind("Status") returns string (True/False), don't know why though it was defined as Boolean in the entity model.

Is there a way to convert Bind("Status") into Boolean value and still using Bind (I need to edit this value not just show it and I think using Bind is the right way to do it automatically instead of doing it by C# code).

I had once the same problem in ASP.Net, but using ADO.Net. I had to map a column that stored Y/N to a checkbox, and the solution was to simply convert the char(1) column to a bit using cast((case when YesNoColumn = 'Y' then 1 else 0 end) as bit) in the select statement, and the binding worked correctly. This, however, requires that the insert and update statements be also modified accordingly. I am not sure how this can be done in Entity Framework though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM