I have a repeater with a CheckBox and a TextBox, that I am binding to a data source. Depending on conditions from the code behind, I want to be able to disable the CheckBox and TextBox dynamically.
Currently this is what I have within the <ItemTemplate>:
<td>
<asp:CheckBox runat="server"
onclick="checkbox(this); CheckChildren(this);"
Enabled='<%#DataBinder.Eval(Container.DataItem, "DISABLE") %>'
Text='<%#DataBinder.Eval(Container.DataItem, "CTEXT") %>'
Value='<%#DataBinder.Eval(Container.DataItem, "CVALUE") %>' />
</td>
<td>
<asp:TextBox runat="server"
onkeyup="AppendValues(this);"
Enabled='<%#DataBinder.Eval(Container.DataItem, "DISABLE") %>'
Width="35px"
MaxLength="3"
Name='<%#DataBinder.Eval(Container.DataItem, "CNAME") %>'
CValue='<%3DataBinder.Eval(Container.DataItem, "CNTVALUE") %>'>
</asp:TextBox>
</td>
The #DataBinder.Eval(Container.DataItem, "DISABLE") is being set to the string value of “true” on the code behind yet when the code is ran, I receive an InvalidCastException exception.
What am I doing wrong?
You need to pass a
booleanvalue to theEnabledproperty. Try something like this