This is probably really simple for someone who's familiar with Javascript, but I have having trouble calling a function while passing an eval as a parameter. I've got a bunch of dynamic checkboxes that I'm trying to create. I've got the text displaying great, but the checkbox is giving me trouble. The problem is, the value that I'm passing to the checkbox is a string (either "true" or "false") not a bool.
<asp:CheckBox runat="server" AutoPostBack="True" Checked='<%# Eval("Value") %>' Text='<%# Eval("DisplayName") %>'></asp:CheckBox>
I also created a short javascript function to convert it to boolean
function ConvertToBoolean(value)
{
if (value == "true")
{ return true;}
if (value == "false")
{ return false;}
}
I'm not great with javascript, but I've tried everything I could find on SO. Not sure why it's not working for me. Here's what I've tried:
Checked='<%# Eval("Value") %>'
Checked="'<%# Eval("Value") %>'"
Checked='<%# "ConvertToBoolean(" + Eval("Value") + ");" %>'
Checked='<%# "ConvertToBoolean(\"" + Eval("Value") + "\");" %>'
Checked='<%# Eval("Value", "javascript:ConvertToBoolean({0});") %>'
Checked="ConvertToBoolean('<%# Eval("Value") %>')"
Am I misunderstanding something fundamental here? Is there even a way to do this?
"Value"? a C# variable? alsoConvertToBooleancould be justreturn (value=="true");Eval