I have this, very common I think, problem...
In the DB there is column name ENABLED which is of type char(1), and contains two "boolean" values: 'Y' or 'N'
In a FormView I want to Bind this column in a checkbox, which should be checked when the column value is 'Y', unchecked otherwise...
Up to now, I am only able to cast it correctly for displaying the value, with something like:
Checked='<%# Eval("ENABLED").ToString() == "S" ? true:false %>'
(or using a code-behind custom function to convert the value).
The problem is when I try to Update the value, because with this code, nothing happens! (the ENABLED parameter isn't passed to the Updating function!)
And if in the above code I change Eval to Bind("ENABLED") I get this error:
Compiler Error Message: CS0103: The name 'Bind' does not exist in the current context
How can I resolve this?
Use bit field instead, you will simply Checked='<%# Eval ("ENABLED") %>' use boolean parameter type, if you want to display it as y/n use select case [enabled] when true then 'y' else 'n'
You, are right, I am calling for trouble...
But I can't change the DB column datatype, because I don't have the permission (and besides the DB is queried by other applications)
Get checkbox using updating event, then set sqldatasource1.updatepatameters("enabled").DefaultValue ="y" based checked value.
沒有留言:
張貼留言